Skip to content

Instantly share code, notes, and snippets.

@Madoshakalaka
Last active December 4, 2020 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Madoshakalaka/dc0fca1b6226d2c255a582f801a5a1fd to your computer and use it in GitHub Desktop.
Save Madoshakalaka/dc0fca1b6226d2c255a582f801a5a1fd to your computer and use it in GitHub Desktop.
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