GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
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 559 remaining answers · ₹2,000 / $25

Every answer, concept and course, every paper breakdown, all published video lessons, hands-on FDE Lab missions, Premium PDF guides and companion files, the full practice-test bank and work-sample downloads. Referral Premium excludes guide PDFs and their companion files.

6 months · One payment · No auto-renewal

Study alongside free video lessons.

Keep practising

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.