Medium · Sliding Window

Minimum Size Subarray Sum

Given an array of positive integers nums and a positive integer target, return the length of the shortest contiguous subarray whose sum is at least target, or 0 if no such subarray exists.

Examples

Example 1

[2,3,1,2,4,3] → 7

Output: 2

Example 2

[1,1,1,1] → 6

Output: 0 (no subarray)

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Sliding Window problems