Minimum Size Subarray Sum
Given an array of positive integers nums and a positive integer target, return the minimal length of a contiguous subarray whose sum is greater than or equal to target. If no such subarray exists, return 0.
Open official problem prompt ↗Find the fewest consecutive elements whose total reaches at least the target.
Filling a bucket from a conveyor: keep adding items until the bucket is heavy enough, then remove from the front to see how light (short) a run still meets the weight.
- Input
- target = 7, nums = [2,3,1,2,4,3]
- Output
- 2
- Why
- The subarray [4,3] sums to 7 (>= 7) and has length 2, the smallest possible.
1 <= target <= 10^91 <= nums.length <= 10^51 <= nums[i] <= 10^4