Skip to content

Longest substring without repeating characters

MediumPython 3StringsSliding windowHash tables

You are given a string s. Return the length of the longest substring (contiguous run of characters) of s that contains no repeated character.

Constraints:
  - 0 <= len(s) <= 5 * 10^4
  - s consists of English letters, digits, symbols and spaces
Examples:
  "abcabcbb" -> 3   ("abc")
  "bbbbb"    -> 1   ("b")
  "pwwkew"   -> 3   ("wke"; "pwke" is a subsequence, not a substring)
  ""         -> 0

Python 3, run in your browser. Run tests runs the problem's own tests with a free account; the AI interviewer reads your code and your runs in a practice interview.

Loading the editor…