Problem · Array
Minimum Workers with Job Assignments
Learn this problemProblem statement
You are given an array jobs. Each entry is [startHHMM, durationMinutes].
Assign every job to a worker so that one worker never handles overlapping jobs. Return an integer array whose first value is the minimum number of workers required and whose remaining values are the assigned worker IDs for jobs in their original input order.
For this exercise, assume:
- Every four-digit
HHMMstart is a valid same-day 24-hour time, every duration is positive, and no job crosses midnight. - A job occupies the half-open interval from its start through start plus duration, so a worker finishing exactly when another job starts is free.
- Process jobs by increasing start minute, breaking equal starts by original input index.
- Worker IDs are positive integers introduced consecutively from
1. Reuse the smallest currently free ID before creating a new one.
Function
assignWorkers(jobs: int[][]) → int[]Examples
Example 1
jobs = [[1030,30],[1045,30],[1100,15]]return = [2,1,2,1]The first two jobs overlap and use workers 1 and 2. At 11:00, worker 1 is free and is the smallest available ID.
Example 2
jobs = [[900,60],[900,30],[930,30]]return = [2,1,2,2]Equal starts are processed by input index. Worker 2 finishes at 09:30 and is reused for the third job.
Constraints
0 <= jobs.length <= 2 * 10^5- Each job has exactly two integers
[startHHMM, durationMinutes]. - Every start is a valid same-day
HHMMvalue. 1 <= durationMinutes, and every job finishes by midnight.