CJCoding With Joseph
15free / daySign inCreate account

Quick Sort With Partition

Write quick_sort(values: list[int]) -> list[int] that returns a new sorted list: a list with at most one element is returned as it is; otherwise take the first element as the pivot, partition the values into three new lists less, equal and greater with one loop and an if / elif / else, then return quick_sort(less) + equal + quick_sort(greater). The equal list is never sorted again, so repeated values cannot cause endless recursion. Quick sort averages O(n log n); a poor pivot on already sorted input makes it O(n squared). Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of space-separated integers (possibly empty); the tests print the list your function returns.

Expected Output:

[1, 3, 3, 4, 6, 8]

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Data Structures & AlgorithmsBig-O
📥 Auto-Input:
3 6 1 8 4 3\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.