Loading practice problems…
Loading your practice workspace…
Loading code editor…
8 / 29
Sign in
Algorithms/Sliding Window

Longest Substring Without Repeating Characters

medium30 min

Given a string s, return the length of its longest contiguous substring with no repeated characters.

The substring must use adjacent characters from the original string.

Example 1

Inputs = "abcabcbb"

Output3

abc has three distinct characters. Every run of four consecutive characters repeats a letter, so the maximum length is 3.

Example 2

Inputs = "bbbbb"

Output1

One b is a valid substring. Any longer substring contains another b, so the maximum length is 1.

Constraints

  • 0 ≤ s.length ≤ 50,000
  • s may contain ASCII letters, digits, spaces, and symbols.
Sliding WindowStringsHash Set