← Core Algorithms
#5 most askedVery commonMediumSliding window

Longest Substring Without Repeating Characters

New to Sliding window? Learn it from scratch first
The Sliding Window Pattern β†’
🏒 Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Return the length of the longest substring of s with no repeated characters.

"abcabcbb" β†’ 3 ("abc"), "bbbbb" β†’ 1, "pwwkew" β†’ 3 ("wke").

πŸ§ͺ Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def length_of_longest(s):
    pass

Output appears here. Press Run or Ctrl/⌘ + Enter.

Try it first. Struggling for a few minutes is how it sticks.