Longest Substring Without Repeating Characters: the skills you need first
Updated
LeetCode · medium · sliding window. A repeat makes the window invalid. Shrink left until the character is unique again.
Skills this problem builds on
Stuck on Longest Substring Without Repeating Characters? It is usually one of these. Get each one solid and the solution stops being a trick.
- Unique-character window shrinks on a repeat
When s[R] already has count 1 in the window, the new count is 2. Shrink L until that character's count is 1, usually L moves to lastIndex[s[R]]+1.
- Maintain distinct count in the window
Distinct is the number of keys with count > 0. Increment distinct when a count goes 0→1. Decrement when a count goes 1→0.
- Track the best valid length
Keep bestLen. When the window is valid, bestLen = max(bestLen, R-L+1). Init bestLen to 0 if empty is allowed.
check which ones you have 10 minutes, free, no account.