Understanding Minimum Size Subarray Sum
Return the length of the shortest contiguous subarray with sum at least target, or 0 if none exists.
How it works
Positive values make shrinking a valid window decrease its sum monotonically.
Expand the right boundary and add its value. While the sum reaches target, record the length and shrink from the left. Return zero when no valid window was found.
Try an example
Input: nums = [2, 3, 1, 2, 4, 3], target = 7
Output: 2
Positive values make shrinking a valid window decrease its sum monotonically.
Constraints
- 0–64 positive integers, each at most 1,000,000.
- Target is an integer from 1 through 64,000,000.
Use the simulator
Change the input, then choose Visualize input. Use Next and Previous to inspect each decision, or Play to advance automatically. Compare approaches and their complexity. Choose Try yourself to write JavaScript, select My code and Visualize code to inspect its execution, or Run Tests to check results.
Execution happens in your browser. Drafts are saved locally; avoid entering secrets or sensitive information.