def partition(arr: List, start: int, end: int) -> int:
"""
Args:
arr (List): the list to partition
start (int): inclusive
end (int): inclusive
Returns:
the pivot index
"""
pivot_index = random.randint(start, end)
pivot = arr[pivot_index]
left = start
right = end
while left <= right:
while arr[left] < pivot:
left += 1
while arr[right] > pivot:
right -= 1
if left <= right:
arr[left], arr[right] = arr[right], arr[left]
left += 1
right -= 1
return left
Chekc if this new implementation is wrong. If it is wrong, can we modify it to make it correct ?
Chekc if this new implementation is wrong. If it is wrong, can we modify it to make it correct ?
refer to https://github.com/OccupyMars2025/Introduction-to-Algorithms-4th-Edition/blob/main/my_implementation/Chapter_07_Quicksort/quicksort/quicksort.py