Trains the technique from
LeetCode 3356Zero Array Transformation 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 row of tanks is numbered from 0, and levels[i] is how many litres tank i currently holds. A maintenance schedule lists pump windows in the order they will run. Window j is windows[j] = [start, end, amount] and means: while that window is open, every tank numbered from start to end inclusive may be drained by any whole number of litres between 0 and amount, chosen separately for each tank. Tanks outside the window are untouched, and a tank can never go below 0.
Return the smallest k such that running only the first k windows of the schedule, in order, is enough to leave every tank empty. Return 0 if the tanks are already all empty, and -1 if running the whole schedule is not enough.
Example 1
With all three windows open, tank 0 can lose 3 litres in the first window and 1 in the second, tank 1 needs nothing, and tank 2 can lose 3 litres in the third window. Two windows leave tank 2 with a draw of only 2 against its 3 litres.
Example 2
The single tank holds 6 litres and the whole schedule offers it a draw of only 2 plus 2, so it cannot be emptied.
Example 3
Tank 0 is already empty. Tank 1 holds 4 litres and is covered by both windows, whose amounts add up to exactly 4.
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 earliest_prefix(levels: list[int], windows: list[list[int]]) -> int:public int earliestPrefix(int[] levels, int[][] windows)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.