 All Problems
Minimum Size Subarray Sum
medium
sliding window
arrays
amazon
google

Given an array of positive integers nums and a positive integer target, return the minimal length of a contiguous subarray whose sum is ≥ target. If there is no such subarray, return 0.

Example 1:

Input: 2 3 1 2 4 3
target: 7
Output: 2
Explanation: [4,3] has the minimum length.

Constraints:

  • 1 ≤ target ≤ 10⁹
  • 1 ≤ nums.length ≤ 10⁵
  • 1 ≤ nums[i] ≤ 10⁴

Input format: First line: space-separated array. Second line: target.

Output format: Minimum subarray length or 0.

Run to check your code against the sample cases, or submit to run every case