A reactor logs n consecutive coolant flow deltas; delta i is the integer a[i] (which may be negative when coolant is drawn off). You want to purge over the shortest possible contiguous window whose delta values sum to at least the threshold t. Report the length of the shortest non-empty contiguous window with sum >= t, or 0 if no window reaches the threshold.
Line 1: an integer n.
Line 2: n space-separated integers, the deltas in order.
Line 3: an integer t, the threshold.
A single integer: the length of the shortest contiguous window whose sum is at least t (0 if none exists).
Example 1
Input
4 1 2 -1 4 4
Expected
1
Explanation
The single element 4 already reaches the threshold, so the shortest window has length 1.
Example 2
Input
3 1 1 1 10
Expected
0
Explanation
Even the whole array sums to only 3, which never reaches 10, so the answer is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →