Skip to main content

Longest Substring Without Repeating Characters

Given a string s, find the length of the longest substring without repeating characters.

Problems12 / 152
Sign in

Longest Substring Without Repeating Characters

MEDIUMStringSliding Window

Given a string s, find the length of the longest substring without repeating characters.

Example 1

Input:  s = "abcabcbb"
Output: 3

Example 2

Input:  s = "bbbbb"
Output: 1
Show hint

Use sliding window technique with a hash map to track character positions. Expand window and shrink when duplicate found.

Draft saves automatically

Loading editor...

Submit also runs hidden tests
s =
"abcabcbb"
Expected
3
Run with your own input (JSON)