Longest Substring Without Repeating Characters
1 approach, code in every language
Problem description
Given a string s, measure the longest stretch of consecutive characters in which every character is unique. Return that length as an integer.
The characters must be adjacent in the original string; picking scattered characters is not allowed.
Example 1
Input: s = "abcabcbb"
Output: 3
The block "abc" has no repeats and is as long as any repeat-free stretch here.
Example 2
Input: s = "bbbbb"
Output: 1
Every character is the same, so the longest unique stretch is a single b.
Constraints
0 <= s.length <= 5 * 10^4s consists of English letters, digits, symbols, and spaces.
Create a free account to see the solution
You get the step-by-step animation, the intuition and clean code in every language. Free, no credit card.
After the pattern
Now solve one you haven't seen.
Largest Clean Tap Block is our own problem on the technique behind Longest Substring Without Repeating Characters: a new statement, so there's no answer to remember. Write it in your browser and run it against graded tests.
1,194 problems · 15,062 graded tests · free