26. Minimum Size Subarray Sum — Positive Inputs
Find the shortest nonempty continuous part of the array whose sum is at least the target. You are minimizing the number of included positions, rather than finding the smallest qualifying sum.
The positive-input restriction is part of this problem. An approach that depends on positivity cannot be reused unchanged when zeros or negative numbers are allowed.
Example 1
Input
target=7, nums=[2,3,1,2,4,3]
Output
2
Explanation: The final [4,3] reaches seven in two positions.
Example 2
Input
target=4294967294, nums=[2147483647,2147483647]
Output
2
Explanation: The sum exceeds int range but is exact as long.
Constraints
0 <= nums.length <= 1051 <= nums[i] <= 231 - 11 <= target <= 263 - 1
Hints
Hint 1
What does strict positivity guarantee about removing the left endpoint?
Hint 2
When a window qualifies, can its shorter suffix still qualify?
Hint 3
Record each valid length and shrink until the sum drops below target.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Shrink several qualifying suffixes
7
[2,3,1,2,4,3]
2