PIXELBANKv9.1.0
Menu

Sort and Search

Problem Statement

Sort NumPy arrays and find elements.

Background

  • np.sort(arr): Returns sorted copy
  • np.argsort(arr): Returns indices that would sort the array
  • np.where(condition): Find indices where condition is True
  • np.argmax(), np.argmin(): Index of max/min element

Your Task

Write a function sort_and_search(arr) that returns a dictionary with:

  • "sorted": Sorted array as list
  • "argsort": Indices that would sort the array
  • "argmax": Index of maximum value
  • "argmin": Index of minimum value

Output Format

Return a dictionary with exactly these four keys.

Example:

Input:
[3, 1, 4, 1, 5, 9, 2, 6]
Output:
{'sorted': [1, 1, 2, 3, 4, 5, 6, 9], 'argsort': [1, 3, 6, 0, 2, 4, 7, 5], 'argmax': 5, 'argmin': 1}
Reasoning:

9 is at index 5 (max), first 1 is at index 1 (min)

Constraints:

  • Use np.sort(), np.argsort(), np.argmax(), np.argmin()
  • Array will have at least 1 element
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Sort and Search - Easy | PixelBank