def max_k_sort(k, nums):
# sort nums first using timsort
# add O(n*log(n)) time complexity
sorted_nums = sorted(nums)
return sorted_nums[-1*k:len(nums)]
def max_k(k, nums):
# build initial max number list
max_nums = {}
# add O(k) time complexity?
i = 0
while i < k:
max_nums[i] = 0
i += 1
# add O(n) time complexity?
least_max_key = min(max_nums, key=max_nums.get)
least_max = max_nums[least_max_key]
# add O(n) time complexity?
for n in nums:
if n > least_max:
max_nums[least_max_key] = n
least_max_key = min(max_nums, …
Run Code Online (Sandbox Code Playgroud)