← Sliding Window

Micro-Drill #103 — Expand/shrink window template

Sliding Window Target: 10s

The generic expand-right / shrink-left template handles all variable-length window problems.

l = 0
for r in range(len(s)):
    # add s[r]
    while invalid():
        # remove s[l]
        l += 1

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #102 Micro #104 →