FDEInterviews logoFDE/Interviews
Coding & DSA / 77
medium★ EssentialAmazonMetaMicrosoft

Longest substring without repeating characters

A sliding window with a last-seen index map, O(n) in one pass. The whole interview turns on one subtlety: when you hit a repeat, the window's left edge must jump forward and never slide backward, which is exactly the bug most candidates ship.

Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.

A sliding window with a last-seen index map, O(n) in one pass. The whole interview turns on one subtlety: when you hit a repeat, the window's left edge must jump forward and never slide backward, which is exactly the bug most candidates ship.

Unlock the other 466 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

The naive set-based window (shrink one char at a time on collision) is O(n) amortized and accepted, but the last-seen-index map is the answer that signals you have seen this pattern before. The trap is the window jump: when the repeated character was last seen at index j, you set left to max(left, j+1), not just j+1. Forgetting the max lets a stale earlier occurrence drag the left edge backward and inflate the count. Make them say why the max is there.

DISCUSSION · 0

No comments yet — be the first to share your approach.