Longest Substring Without Repeating Characters
Medium · Sliding Window
You are given a string. Find the length of the longest contiguous run of characters in it that contains no repeated character. Return that length as an integer.
Examples
Input: s = "abcabcbb"
Output: 3
Why: The longest run with no repeated character is "abc", which has length 3.
Input: s = "bbbbb"
Output: 1
Why: Every character is the same, so the best we can do is a single character.
Input: s = "pwwkew"
Output: 3
Why: "wke" is the longest stretch without a repeat; "pwke" is not contiguous in the original string so it doesn't count.
Constraints
0 <= s.length <= 5 * 10^4, s consists of English letters, digits, symbols and spaces.
Practise it by voice
Describe the solution out loud and the interviewer writes exactly what you say, asks when you are vague, and runs the tests in your browser.
Practise Longest Substring Without Repeating Characters
This statement is written for CodeSpeek. The problem is part of the NeetCode 150 list; Watch NeetCode's explanation of Longest Substring Without Repeating Characters. Reference solutions from the NeetCode repository (MIT) are used to verify our tests.