Longest Substring Without Repeating Characters
Medium · Sliding Window · Hash Table · String · Sliding Window
Problem
Given a string s, return the length of the longest substring with no repeated characters.
A substring is contiguous — "pwke" is a subsequence of "pwwkew", not a substring.
Examples
Input: s = "abcabcbb" Output: 3
"abc" is the longest window.
Input: s = "bbbbb" Output: 1
"b".
Input: s = "pwwkew" Output: 3
"wke". "pwke" is not contiguous.
Constraints
- 0 <= len(s) <= 5 * 10^4
- s may contain letters, digits, symbols and spaces
Approaches
- Brute force — every substring — time O(n³), space O(n)
Related problems
Start free on Cariara · Coding problems · System design studio