Skip to content
Decoder

Longest Substring Without Repeating Characters

Medium

Problem

Given a string s, return the length of the longest substring that has no repeated characters. A substring is a contiguous run of characters, so "pwke" does not count for "pwwkew".

Example 1

Input
"abcabcbb"
Output
3
Why
"abc"

Example 2

Input
"bbbbb"
Output
1
Why
"b"

Example 3

Input
"pwwkew"
Output
3
Why
"wke"

Constraints

  • 0 <= s.length <= 5 * 10^4
  • s consists of English letters, digits, symbols and spaces.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.