Trains the technique from
LeetCode 2365Task Scheduler IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
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
All three jobs are of different kinds, so no wait ever bites and they go on three days running.
Example 3
The three jobs share a kind and two whole days must pass between them, so they go on days one, four and seven.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def task_scheduler_i_i(jobs: list[int], gap: int) -> int:public long taskSchedulerII(int[] jobs, int gap)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.