Shortest positive-sum window
For positive integer values return the shortest contiguous subarray with sum at least target, or zero when impossible. target is positive.
window = [2, 3, 4]
target = 7
print(sum(window), sum(window[1:]))Reason about the state
Positive values make window sums monotone as either endpoint moves. Shrink every qualifying window to find its smallest version in linear time. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
For positive integer values return the shortest contiguous subarray with sum at least target, or zero when impossible. target is positive.
The explanation opens here once every check passes.