Skip to the code
+10 XP

#381 Slowest Loads Leaderboard

easy

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.

Example 1

Input: times = [320,150,900,410,220], k = 2
Output: 410

From slowest: 900, 410, 320, 220, 150. The 2nd is 410.

Example 2

Input: times = [300,300,100], k = 2
Output: 300

Repeated times count separately: 300, 300, 100.

Constraints

  • 1 <= k <= times.length <= 2 * 10^5
  • 1 <= times[i] <= 10^5
Saved in this browser

Run 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).