← Pointer Manipulation

Micro-Drill #90 — Variable window (min length)

Pointer Manipulation Target: 15s

Variable window expands right and shrinks left when the condition is met. Classic pattern.

left = 0
cur_sum = 0
best = float('inf')
for right in range(len(a)):
    cur_sum += a[right]
    while cur_sum >= target:
        best = min(best, right - left + 1)
        cur_sum -= a[left]
        left += 1

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #89 Micro #91 →