Sliding Window
LC #209Medium
Minimum Size Subarray Sum
Sliding Window
AmazonGoogleMetaProblem
Given an array of positive integers and a target, find the minimal length of a subarray whose sum is ≥ target.
arraysliding-windowprefix-sum
Constraints
- ›1 ≤ n ≤ 10⁵
- ›1 ≤ target ≤ 10⁹
- ›1 ≤ nums[i] ≤ 10⁴
Example
Input
target = 7, nums = [2, 3, 1, 2, 4, 3]Output
2Why
[4, 3] has sum ≥ 7 with minimum length 2