A regional relay race uses a single electronic baton that beeps and logs a timestamp every time it changes hands. Officials kept a log of exactly n handoffs, each entry recording the runner id who finished a leg and the exact time (in seconds since the starting gun) at which they handed the baton to the next runner. The very first leg begins at time 0, and every later leg begins exactly when the previous leg ended. The same runner id can appear in more than one entry, since a runner may run several legs over the course of the race. Determine the id of the runner who held the baton for the single longest leg; if two or more runners tie for the longest leg, report the smallest such id.
n, the number of logged handoffs.n lines contains two integers id and t, meaning the runner with id id finished a leg at time t. The lines are given in strictly increasing order of t.A single integer: the id of the runner with the longest single leg, breaking any tie by reporting the smallest id.
t strictly increase from line to line.Example 1
Input
4 0 3 2 5 0 9 1 15
Expected
1
Explanation
The legs and their durations are: runner 0 from 0 to 3 (3s), runner 2 from 3 to 5 (2s), runner 0 from 5 to 9 (4s), and runner 1 from 9 to 15 (6s). Runner 1's 6-second leg is the longest, so the answer is 1.
Example 2
Input
3 0 5 1 10 2 15
Expected
0
Explanation
Each leg lasts exactly 5 seconds (0->5, 5->10, 10->15), a three-way tie between runners 0, 1, and 2. The tie is broken by the smallest id, so the answer is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →