Trains the technique from
LeetCode 1335Minimum Difficulty of a Job ScheduleThis 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 film archive restores reels in a fixed queue order. jobDifficulty[i] is the wear rating of the reel at position i, and the queue must be handled in exactly d shifts.
A shift takes a contiguous run of reels from the front of what is left, and every shift has to take at least one reel. The technician on a shift is billed for the single worst reel they touched, so a shift costs the largest wear rating inside its run. The bill for the whole plan is the sum over the d shifts.
Return the smallest possible bill. If the queue cannot be cut into d non-empty runs at all, return -1.
Example 1
The plan [4, 1, 9] then [2] uses two contiguous non-empty runs and is billed 9 + 2 = 11.
Example 2
The plan [7], [3, 5, 8], [2] is billed 7 + 8 + 2 = 17, and each of its three runs is non-empty and contiguous.
Example 3
Only two reels are queued, so three non-empty runs cannot be formed and the sentinel is returned.
Example 4
Each shift must take exactly one reel and every reel is rated 5, so the bill is 5 + 5 + 5.
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 cheapest_shift_plan(reels: list[int], shifts: int) -> int:public int cheapestShiftPlan(int[] reels, int shifts)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.