← All Patterns

Pattern Recognition Drill

#102

Medium Sliding Window

The Problem

Given a string, find the length of the longest substring without repeating characters.

What approach would you use?

Think about it before scrolling down.

Longest Substring Without Repeating Characters

Key Signals

Sliding Window

Expand right; when duplicate found, shrink left past the previous occurrence. O(n).

Alt: Hash Map

Map char → last index to jump left pointer directly instead of shrinking one by one.

Common Trap

Don't restart from scratch when a duplicate is found — just slide the left pointer forward.

← #101 #103 →