Problem
FAANG · LeetCode #209

Minimum Size Subarray Sum — three-stage drill

1The ProblemMedium

Minimum Size Subarray Sum

Shortest contiguous subarray whose sum is at least the target.

shortest subarray with sum ≥72031122344354 + 3 = 7 ≥ 7, length 2return2
Examples
[2,3,1,2,4,3], t=7→ 2[1,2,3], t=7→ 0

constraintAll numbers are positive (1 ≤ nums[i]).

2The PatternTIME O(n) · SPACE O(k)

Sliding Window

A contiguous window that grows and shrinks to stay valid.

expand right · shrink left to keep the window valida0b1c2d3e4f5l = r›
Problems using this pattern
3The SolutionRESULT → 2

Step through it

target = 7↩ ANSWERshortest =—203112234435l = r›sum = 2
right → 0: add 2. sum = 2 < 7
Step 1 / 11
Arrow keys to navigate · escape to reset

All problems by pattern

Backtracking

Recursive Descent