JuniorArray

The Employee That Worked on the Longest Task

There are n employees, each with a unique id from 0 to n - 1.

You are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where:

  • idi is the id of the employee that worked on the i^th task.
  • leaveTimei is the time at which the employee finished the i^th task. All the values leaveTimei are unique.

Note that the i^th task starts the moment right after the (i - 1)^th task ends, and the 0^th task starts at time 0.

Return the id of the employee that worked the task with the longest time. If there is a tie between two or more employees, return the smallest id among them.

Example 1
Inputn = 10, logs = [[0,3],[2,5],[0,9],[1,15]]
Output1
Task 3 has the longest duration, 6 units of time, and it was worked by employee 1.
Example 2
Inputn = 26, logs = [[1,1],[3,7],[2,12],[7,17]]
Output3
Task 1 has the longest duration, 6 units of time, and it was worked by employee 3.

Constraints

  • 2 <= n <= 500
  • 1 <= logs.length <= 500
  • logs[i].length == 2
  • 0 <= idi <= n - 1
  • 1 <= leaveTimei <= 500
  • idi != idi+1
  • leaveTimei are sorted in a strictly increasing order.

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