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:
idiis the id of the employee that worked on thei^thtask.leaveTimeiis the time at which the employee finished thei^thtask. All the valuesleaveTimeiare 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
Input
n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]Output
1Task 3 has the longest duration, 6 units of time, and it was worked by employee 1.
Example 2
Input
n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]Output
3Task 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.