All problemsBack
Longest Substring Without Repeating Characters
mediumGiven a string s, find the length of the longest substring without repeating characters.
Test Cases
Copy an input into themain harness and Run to verifyInput
s = "abcabcbb"Expected Output
3Explanation: The answer is "abc", with the length of 3.
Input
s = "bbbbb"Expected Output
1Input
s = "pwwkew"Expected Output
3Explanation: The answer is "wke". Note that "pwke" is a subsequence, not a substring.
Constraints
- 0 <= s.length <= 5 * 10^4
- s consists of English letters, digits, symbols and spaces.
Hints
Hint 1 — click to reveal
Use a sliding window with two pointers.
Hint 2 — click to reveal
When a repeat is found, move the left pointer past the previous occurrence.
Java Compiler
Powered by OneCompiler. Starter code loads automatically — edit and hit Run.