Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from typing import List
def quick_sort_find_n_th_largest(numbers: List[float], n: int) -> float:
pivot = numbers[0]
left = []
right = []
for num in numbers[1:]:
if num >= pivot:
left.append(num)
else:
right.append(num)
len_left = len(left)
diff = n - len_left
if diff > 1:
return quick_sort_find_n_th_largest(right, diff-1)
elif diff == 1:
return pivot
else:
return quick_sort_find_n_th_largest(left, n)
list_1 = [1,2,3,4,5,6,7,8,]
print(quick_sort_find_n_th_largest(list_1, 1))
print(quick_sort_find_n_th_largest(list_1, 2))
print(quick_sort_find_n_th_largest(list_1, 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment