Loading practice problems…
Loading your practice workspace…
Loading code editor…
9 / 29
Sign in
Algorithms/Sliding Window

Minimum Size Subarray Sum

medium30 min

Given an array of positive integers nums and a positive integer target, return the smallest length of a contiguous subarray whose sum is at least target.

Return 0 when no qualifying subarray exists.

Example 1

Inputtarget = 7, nums = [2, 3, 1, 2, 4, 3]

Output2

[4, 3] reaches the target.

Example 2

Inputtarget = 4, nums = [1, 4, 4]

Output1

Constraints

  • 1 ≤ nums.length ≤ 100,000
  • All values and target are positive integers.
Sliding WindowArrays