Ctrl K

Shortest Server Uptime

Hard
A server can run any number of jobs at the same time. Each job is a triple jobs[i] = [start, end, duration]: it needs duration seconds of server time in total, somewhere within the seconds from start to end inclusive. Those seconds do not have to be consecutive. In every second the server is either on (and then every job whose window contains that second may make progress) or off. Return the smallest number of seconds the server has to be on so that every job gets done.
Example 1
jobs=[[1, 4, 2], [3, 6, 2], [6, 8, 1]] → 3

Switch the server on at seconds 3, 4 and 6: the first job runs at 3 and 4, the second at 4 and 6, the third at 6. That is 3 seconds.

Example 2
jobs=[[2, 3, 2], [5, 5, 1]] → 3

The windows do not overlap and both jobs fill their windows completely: 2 + 1 = 3.

Example 3
jobs=[[1, 10, 3], [4, 6, 3]] → 3

The second job needs seconds 4, 5 and 6, and the first job can run in those very seconds.

Constraints
  • 1 ≤ len(jobs) ≤ 2000
  • 1 ≤ start ≤ end ≤ 2000
  • 1 ≤ duration ≤ end - start + 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSorting Batches With Repeats HardLifters and Energy Drinks HardKeep Every Lamp Running HardFlowerbed Beauty on a Budget HardCommon Setting at Different Step Prices Hard
loading Python…
Input
jobs=[[1, 4, 2], [3, 6, 2], [6, 8, 1]]
Expected
3

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