A team logs a positive integer output for each of n consecutive days. Find the shortest contiguous run of days whose total output is at least the quota s, and report its length. If no run reaches the quota, report 0.
Line 1: two integers n and s.
Line 2: n space-separated positive integers, the daily outputs.
A single integer: the length of the shortest contiguous window with sum at least s, or 0 if none exists.
Example 1
Input
6 8 2 6 1 3 5 2
Expected
2
Explanation
The window [2, 6] already reaches 8 with length 2; no single day is at least 8, so 2 is the shortest.
Example 2
Input
3 100 1 2 3
Expected
0
Explanation
The entire log sums to only 6, which never reaches 100, 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 →