MediumHash TableStringSliding Window

Longest Substring Without Repeating Characters

LeetCode
1 approach, code in all languages

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^4
  • s consists of English letters, digits, symbols, and spaces.
You've got the patterns

Patterns get you through the screen. Shipping gets you hired.

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

August 15 · 0d left
Enroll Now