Longest Substring Without Repeating Characters

Medium#3variable size

You get a string. Find the length of its longest piece of letters in a row where no letter repeats. Our example: "abcbdae" — the answer is 5, the piece "cbdae".

input
s: a string; spaces, digits and symbols are characters too.
returns
The length of the longest substring of s in which no character repeats.
constraints
  • 0 ≤ s.length ≤ 10000
  • s: English letters, digits, symbols and spaces
our 12 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.
/**
 * @param {string} s
 * @return {number}
 */
function lengthOfLongestSubstring(s) {

}
Ctrl ↵
format
reset

saved in this browser

12 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more sliding window problems

Pattern “Sliding window” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.