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.

30:00

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:
  • 1target1091 \leq \text{target} \leq 10^9

  • 1nums.length1051 \leq \text{nums.length} \leq 10^5

  • 1nums[i]1041 \leq \text{nums}[i] \leq 10^4

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.

Variables
No variables to display
DepthFunction Call
1minSubArrayLen(target=7, nums=[6])
0/20