Gamified challenge · Quickselect
scores holds every athlete's score. Ranked from best (largest) to worst, repeated scores each take their own place, so in [72, 95, 88, 61, 95, 80] both 95s take places 1 and 2.
Write kthLargest(scores, k) that returns the score in place k (1 ≤ k ≤ number of scores). For the example and k = 2 the answer is 95; for k = 3 it is 88.
There can be thousands of scores: a full sort works, but try quickselect, which partitions round a pivot and only keeps the side holding place k.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google