FDEInterviews logo
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.

20 answers per topic instead of 10, plus saved progress and bookmarks · no cardor unlock all 528 remaining answers · ₹2,000 / $25
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.