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.See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI