Ctrl K

Jobs in Order With Rest Days

Medium
You get a list of jobs jobs, where jobs[i] is the kind of the i-th job. The jobs must be done strictly in the given order. Each day you either do the next job or take a day off. Once a job of some kind is done, the next job of the same kind may only be done after at least rest days have passed. Return the smallest number of days needed to finish all the jobs.
Example 1
jobs=[7, 3, 7, 7], rest=2 → 7

Day 1: 7, day 2: 3, day 3: rest, day 4: 7, days 5–6: rest, day 7: 7.

Example 2
jobs=[1, 2, 3, 1], rest=2 → 4

Two days already pass between the two jobs of kind 1, so no rest is needed.

Example 3
jobs=[5, 5], rest=1 → 3
Constraints
  • 1 ≤ len(jobs) ≤ 10⁵
  • 1 ≤ jobs[i] ≤ 10⁹
  • 1 ≤ rest ≤ len(jobs)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsHow Far the Rover Got MediumLast Step With a Lit Run MediumFully Dug Relics MediumA Chain of Replacements MediumRows That Match Columns Medium
loading Python…
Input
jobs=[7, 3, 7, 7], rest=2
Expected
7

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