Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Quicksort

Sortingmedium

Course · Section 11: Working With Arrays · Lecture 172: Sorting Arrays

Implement `quickSort(arr)` returning the array sorted ascending using quicksort.

Sample tests

Input: quickSort([3,6,1,8,2])
Output: [1,2,3,6,8]
Input: quickSort([])
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • A bad pivot on already-sorted input degrades to O(n^2).

Learning resources

  • MDN: Array.prototype.sort
Approach & explanation (try first)

Quicksort partitions around a pivot and recurses. Average O(n log n), worst O(n^2).

Loading...
⌘/Ctrl + Enter

Run your code to see results.