Skip to content
DeepForgeby svx
All problems
MediumAlgorithmsal-019

Quick Sort

Problem

Sort a list of integers in ascending order and return the sorted list using quicksort with Lomuto partitioning.

Choose the last element as the pivot, partition the range so all smaller or equal elements come first, then recurse on both sides of the pivot. Return a new list and handle duplicates and empty input.

Hint

Lomuto partition walks j through the range and swaps every element not greater than the pivot behind index i.

Test cases

case 1
in: [[10,7,8,9,1,5]]
expected: [1,5,7,8,9,10]
case 2
in: [[]]
expected: []
case 3
in: [[3,3,3]]
expected: [3,3,3]
case 4
in: [[-2,5,0,-2]]
expected: [-2,-2,0,5]
Starter codePython
def quick_sort(arr):
    # Your code here
    pass

4 test cases · run your code against them in the editor