JuniorArray

Button with Longest Push Time

You are given a 2D array events which represents a sequence of events where a child pushes a series of buttons on a keyboard.

Each events[i] = [indexi, timei] indicates that the button at index indexi was pressed at time timei.

  • The array is sorted in increasing order of time.
  • The time taken to press a button is the difference in time between consecutive button presses. The time for the first button is simply the time at which it was pressed.

Return the index of the button that took the longest time to push. If multiple buttons have the same longest time, return the button with the smallest index.

Example 1
Inputevents = [[1,2],[2,5],[3,9],[1,15]]
Output1
Button 1 takes 2 units on its first press and 6 units on its second press, which is the longest duration.
Example 2
Inputevents = [[10,5],[1,7]]
Output10
Button 10 takes 5 units while button 1 takes 2 units, so button 10 has the longest push time.

Constraints

  • 1 <= events.length <= 1000
  • events[i] == [indexi, timei]
  • 1 <= indexi, timei <= 10^5
  • The input is generated such that events is sorted in increasing order of timei.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate