A performance dashboard collects page load times in milliseconds. To set an alert threshold, the team wants the k-th slowest load: the k-th largest value when the times are sorted from slowest to fastest, counting repeated times separately.
Write kthSlowest(times, k) that returns that value. k is between 1 and times.length. Try to use only O(k) extra memory.
Input: times = [320,150,900,410,220], k = 2 Output: 410
From slowest: 900, 410, 320, 220, 150. The 2nd is 410.
Input: times = [300,300,100], k = 2 Output: 300
Repeated times count separately: 300, 300, 100.
1 <= k <= times.length <= 10^51 <= times[i] <= 10^5Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #381 Slowest Loads Leaderboard. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.