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.
Java
Minimum Size Subarray Sum
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
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.