Longest Substring Without Repeating
Difficulty: Medium · Topic: Arrays & strings
Given a string s, return the length of the longest substring without repeating characters. Slide a window; when a character repeats inside it, jump the window start past the previous occurrence.
Examples
length_of_longest_substring("abcabcbb")
→ 3'abc' has length 3.
length_of_longest_substring("bbbbb")
→ 1length_of_longest_substring("pwwkew")
→ 3'wke' — note 'pwke' is not a substring.
Target complexity: time O(n), space O(min(n, alphabet))
Write your solution in Python and run it against hidden tests right on this page. Progressive hints and Python + C++ reference solutions are included.
Learn the idea first: the lesson for this problem.