Find the Kth largest element in an array. How many approaches can you think of? Code any two of them.
Asked in the technical interview stage. The interviewer wanted Quickselect; the candidate coded sorting and a min-heap. Reported follow-ups included discussing the complexity of each approach.
Implement kth_largest(nums, k). nums is a non-empty list of integers, and k is a valid 1-based rank. Return the kth largest value. Treat duplicate values as separate elements.
def kth_largest(nums, k):