Trains the technique from
LeetCode 862Shortest Subarray with Sum at Least KThis 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 tidal power station logs its net contribution to the grid once a minute. net[i] is the number of kilowatt-hours the station delivered during minute i, and the figure is negative for a minute in which the station drew more from the grid than it delivered, which happens while the sluices are being refilled around slack water.
A run is a block of one or more consecutive minutes, and its yield is the total of the logged figures across those minutes.
The operator has to show one run whose yield is at least quota, and wants the shortest such run. Return the number of minutes in the shortest run whose yield is at least quota. If no run reaches quota at all, return -1.
Example 1
The three minutes together yield 4 - 1 + 4 = 7, which meets the quota; neither single minute nor either pair of neighbouring minutes reaches 7.
Example 2
The last minute on its own yields 100, comfortably past a quota of 2, and a run cannot be shorter than one minute.
Example 3
The log holds one run, and its yield of 17 falls short of the quota.
Example 4
The last three minutes yield 6 - 1 + 4 = 9, exactly the quota, while no single minute and no neighbouring pair reaches 9.
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 shortest_run(net: list[int], quota: int) -> int:public int shortestRun(int[] net, int quota)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.