Ctrl K

Who Spent Longest on One Task

Easy
A team has staff employees numbered 0 to staff - 1. They worked through tasks one after another with no breaks: the first task started at time 0, and each next task started the moment the previous one ended. You are given a list records where records[i] = [who, end]: task i was done by employee who and finished at time end. Finish times are strictly increasing, and no employee takes two tasks in a row. Return the id of the employee who spent the most time on a single task. If several tasks share the longest time, return the smallest id among the people who did them.
Example 1
staff=4, records=[[2, 4], [0, 6], [3, 13], [1, 15]] → 3

The tasks took 4, 2, 7 and 2 time units. The longest is the third one (from 6 to 13), done by employee 3.

Example 2
staff=5, records=[[4, 5], [1, 10], [4, 12]] → 1

The first two tasks took 5 each, done by employees 4 and 1, so we return the smaller id, 1.

Constraints
  • 2 ≤ staff ≤ 500
  • 1 ≤ len(records) ≤ 500
  • 0 ≤ who ≤ staff - 1
  • 1 ≤ end ≤ 500
  • The end values are strictly increasing
  • Consecutive records belong to different employees
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
staff=4, records=[[2, 4], [0, 6], [3, 13], [1, 15]]
Expected
3

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