Skip to main content
CodeOath
← All problems

Problem

Longest Substring Without Repeating Characters

Medium
  • strings
  • sliding-window

Return the length of the longest substring of s in which no character appears twice. A substring is a run of neighbouring characters, so you cannot skip characters inside it.

Example 1
Input
s = "abbcdab"
Output
4
Explanation

"bcda" and "cdab" both have four different characters. No run of five is free of repeats.

Example 2
Input
s = "aaaa"
Output
1
Explanation

every character is the same, so the longest run without a repeat is a single character.

Example 3
Input
s = ""
Output
0
Explanation

an empty string has no characters at all.

Constraints:

  • 0 <= s.length <= 10^5
JavaScript

Tab indents. Press Esc, then Tab to leave the editor.

Run your code to see every test here. Nothing is submitted or recorded.