Back to problems Solve on LeetCode →

Longest Substring Without Repeating Characters

LeetCode 3 • Medium • Sliding Window

Find the length of the longest substring without repeating characters.
Input: s = "abcabcbb"  →  Output: 3 (substring "abc")

TimeO(n)each char at most 2x
SpaceO(min(n,128))char set
Window
Right (expand)
Shrink
Result
Window
Set
MaxLen
Ready
Press Play. Expand right, add char to set. If duplicate, shrink from left until unique. Track max length.