← Pointer Manipulation

Micro-Drill #91 — Longest substring template

Pointer Manipulation Target: 15s

Set-based window tracks unique characters. Shrink left when a duplicate enters.

seen = set()
left = 0
best = 0
for right in range(len(s)):
    while s[right] in seen:
        seen.remove(s[left])
        left += 1
    seen.add(s[right])
    best = max(best, right - left + 1)

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #90 Micro #92 →