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.
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.
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.
No comments yet — be the first to share your approach.
