A performance report lists page load times in milliseconds in times, in no particular order. To flag outliers, it needs the k-th slowest load: the k-th largest value, counting repeats (so k = 1 is the slowest).
Write kthSlowest(times, k) that returns it. Try for average O(n) time, faster than sorting.
Input: times = [320,150,980,410,150], k = 2 Output: 410
Slowest first: 980, 410, 320, 150, 150. The 2nd is 410.
Input: times = [320,150,980,410,150], k = 5 Output: 150
The 5th slowest is the fastest load.
1 <= k <= times.length <= 2 * 10^50 <= times[i] <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #214 Kth Slowest Page Load. 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.