Trains the technique from
LeetCode 1526Minimum Number of Increments on Subarrays to Form a Target ArrayThis 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 canal towpath is split into n numbered sections laid end to end. The surveyor has written down how thick the sealant on each section must finish: section i needs exactly coats[i] coats. The path starts bare.
A sealant lorry works in runs. One run chooses a contiguous block of sections, drives the block once, and leaves exactly one further coat on every section inside it. A block may be as short as one section or as long as the whole path, and later runs may overlap earlier ones however you like.
Sealant cannot be lifted once laid, so no section may finish with more coats than the surveyor asked for, and none may finish with fewer.
Return the fewest runs that leave every section at its written thickness.
Example 1
Two runs, each driving the whole path, leave every section with two coats.
Example 2
One run over all three sections, one over the last two, then two more over the middle section alone: the sections finish at one, four and two coats.
Example 3
Three runs over the first section only, one over the whole path, then two over the last section only, finishing at four, one and three coats.
Example 4
Seventeen runs suffice: two over the whole path, then five more over each of the first, third and fifth sections taken singly.
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 min_number_operations(coats: list[int]) -> int:public int minNumberOperations(int[] coats)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.