Problem statement
Given an array of positive numbers and a target, find the shortest run of neighbours whose sum is at least the target. The run must be contiguous, and its values are all positive.
If no run reaches the target, the answer is 0. That is not a length the array can have, which is what makes it a safe marker for no answer.
Examples
Input[2, 3, 1, 2, 4, 3], target = 7
Output2
The run 4, 3 adds to 7 and is the shortest that reaches it.
Input[1, 1, 1], target = 9
Output0
Every value together adds to 3, so no run reaches the target.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing