loading

Minimum Size Subarray Sum — Step-by-Step Visualization

mediumLeetCode #209ArrayBinary SearchSliding Window

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 no such subarray exists, return 0.

Algorithm Pattern

Sliding Window

Key Idea

Expand right pointer to grow sum, shrink left pointer when sum satisfies condition.

Step-by-Step Approach

  1. Expand window by moving right
  2. When sum >= target, record length
  3. Shrink window from left, repeat

Related Problems