Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0.
30:00
Java
Minimum Size Subarray Sum
medium
Topics
Companies
Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0.
Example 1:
Input: {"target":7,"nums":[2,3,1,2,4,3]}
Output: 2
Constraints:
1≤target≤109
1≤nums.length≤105
1≤nums[i]≤104
Input
arr ={"target":7,"nums":[2,3,1,2,4,3]}
nums (target = 7)203112234435
Left:
0
Window Sum:
0
Min Length:
∞
Algorithm Insight:
Expand window by moving right pointer. When sum ≥ target, shrink from left while maintaining validity. Track minimum window length throughout.