Task Scheduler II
Real-world version: How Many Days the Run of Jobs TakesThe statement here is our own: the same inputs, outputs and technique.
A run of jobs reads jobs, taken strictly in the order given, and each entry names the job's kind. Days are counted from one.
On any day you may either finish the next job in the run or take the day off, but a job may only be finished when at least gap whole days have passed since the last job of the same kind was finished.
Return the fewest days the whole run takes, counting the day the last job is finished.
Examples
Example 1
- Input
- jobs = [1, 1], gap = 1
- Output
- 3
The first job goes on day one. The second is the same kind and one whole day has to pass, so day two is out and it goes on day three.
Example 2
- Input
- jobs = [1, 2, 3], gap = 5
- Output
- 3
All three jobs are of different kinds, so no wait ever bites and they go on three days running.
Example 3
- Input
- jobs = [4, 4, 4], gap = 2
- Output
- 7
The three jobs share a kind and two whole days must pass between them, so they go on days one, four and seven.
Constraints
- 1 <= jobs.length <= 10^5
- 1 <= jobs[i] <= 10^9
- 1 <= gap <= jobs.length
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def task_scheduler_i_i(jobs: list[int], gap: int) -> int:public long taskSchedulerII(int[] jobs, int gap)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Find Winner on a Tic Tac Toe GameReal-world version: Who Comes Out Ahead on the Three-by-ThreeEasy
- Make Array Zero by Subtracting Equal AmountsReal-world version: Rounds Needed to Clear Every ReadingEasy
- Minimum Pair Removal to Sort Array IReal-world version: Merging the Smallest Neighbouring Pair Until the Strip RisesEasy
- Walking Robot SimulationReal-world version: Sweeper Drone SortieMedium