InferenceAI

Enter at least two characters to search.

Start free

Minimum Size Subarray Sum

mediumSliding Window25 min25 XP

Given positive integers nums, return the length of the shortest contiguous subarray whose sum is at least target, or 0 if none exists.

Examples

EXAMPLE WALKTHROUGHclassic

A guided view of the published example, not a trace of your code.

INPUT[7,[2,3,1,2,4,3]]
TASKminimum_size_subarray()
EXPECTED OUTPUT2

Start with the input values shown in this example.

Example 1 of 3

Input: target = 7, nums = [2,3,1,2,4,3]

Output: 2

Explanation: classic

Input: target = 4, nums = [1,4,4]

Output: 1

Explanation: single element

Input: target = 11, nums = [1,1,1,1,1]

Output: 0

Explanation: impossible

Hint 1

Grow the window to the right, then shrink from the left while the sum still reaches the target.

Topics

DSASliding WindowPython