Ctrl K

The Slowest Keypress

Easy
Someone is typing, and a logger records every keypress as a pair [key, at]: the key number and the moment it was pressed. The entries in presses are in increasing order of time. A press lasts from the previous press until this one. The very first press lasts exactly at (the clock starts at zero). Return the number of the key whose press lasted longest. If several presses tie, return the smallest key number. The same key may show up more than once; each press counts on its own.
Example 1
presses=[[4, 3], [7, 4], [2, 10], [9, 12]] → 2

Durations: key 4 took 3, key 7 took 1, key 2 took 6, key 9 took 2. Key 2 was the slowest.

Example 2
presses=[[8, 5], [3, 10]] → 3

Both keys took 5 time units; on a tie we pick the smaller key number, 3.

Example 3
presses=[[6, 1], [6, 5], [1, 6]] → 6
Constraints
  • 1 ≤ len(presses) ≤ 1000
  • presses[i] = [key, at]
  • 1 ≤ key, at ≤ 10⁵
  • The at values are strictly increasing
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
presses=[[4, 3], [7, 4], [2, 10], [9, 12]]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.