Minimum Size Subarray Sum
Practice this coding question on Coding Gurukul.
Problem statement
A fundraising tracker records positive daily donations. A coordinator wants the shortest uninterrupted run of days whose total reaches a target, so that the campaign can highlight its most concentrated successful period. Your task Find the minimum length of a contiguous subarray with sum at least target. Return 0 if no such subarray exists. Important details Every value is positive, allowing a sliding window to grow and shrink monotonically. A sum greater than target is acceptable. Do not combine separated days or assume that the shortest section begins at the first day. Worked example For [2, 3, 1, 2, 4, 3] and target 7, the final two values 4 and 3 reach the target. No single value does, so the answer is 2.
Input format
First line: n target. Next line: n positive integers.
Output format
Print the minimum length, or 0.
Constraints
1 <= n <= 100000; 1 <= values <= 10000; 1 <= target <= 1000000000.
Sample input
6 7 2 3 1 2 4 3
Sample output
2
Sign in to run or submit a solution in C++, Java or Python.