MediumPro challengePythonJavaScriptTypeScript
Quicksort
AlgorithmsSortingRecursion
Implement solve(arr) that sorts an array of numbers using the
quicksort algorithm. Return a new sorted array — don't mutate the input.
Constraints
- Do not use
Array.prototype.sort. - Average O(n log n) time.
Sample tests
Test #1Single element
Input: [[1]]
Output: [1]
Test #2Unsorted array with duplicate
Input: [[3,1,4,1,5,9,2,6]]
Output: [1,1,2,3,4,5,6,9]
Test #3Empty array
Input: [[]]
Output: []
Test #4Reverse sorted
Input: [[5,4,3,2,1]]
Output: [1,2,3,4,5]
Test #5All identical
Input: [[2,2,2,2]]
Output: [2,2,2,2]