FunctionRacerProblemsRace

Minimum Size Subarray Sum

MediumTwo pointersPython, JavaScript, TypeScript, Java, C++

All items of nums are positive. Find the shortest contiguous stretch whose sum is at least target, and return its length.

Return 0 if no stretch is big enough.

Example 1

target 7
nums [2,3,1,2,4,3]
returns 2

The stretch [4, 3] sums to 7.

Example 2

target 100
nums [1,2,3]
returns 0

Even the whole list is too small.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems