Back

Longest Substring Without Repeating Characters

medium

Given a string s, find the length of the longest substring without repeating characters.

Test Cases

Copy an input into the main harness and Run to verify
Input
s = "abcabcbb"
Expected Output
3

Explanation: The answer is "abc", with the length of 3.

Input
s = "bbbbb"
Expected Output
1
Input
s = "pwwkew"
Expected Output
3

Explanation: 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.