ArraySliding WindowPrefix Sum
Given an array of positive integers and a target, find the length of the shortest contiguous subarray whose sum is at least the target. If there is no such subarray, the answer is 0.
Input
Line 1: n and the target. Line 2: n positive integers.
Output
Print the minimal length, or 0 if no subarray reaches the target.
Constraints
1 <= n <= 10^5 1 <= each value <= 10^4 1 <= target <= 10^9
Example 1
Input
6 7 2 3 1 2 4 3
Output
2
The subarray [4, 3] sums to 7 and no shorter one does.