Asked at

Longest Substring Without Repeating Characters

Medium
Verified
StringSliding WindowHash Map~25 min

Given a string s, return the length of the longest substring that contains no repeating characters.

Slide a window forward and remember the last index of each character; when a repeat falls inside the window, jump the left edge past it. The input arrives as a single string s.

Examples

in"abcabcbb"
out3

The longest substring without a repeat is "abc".

in"bbbbb"
out1

The longest substring without a repeat is "b".

Constraints

  • 0 ≤ s.length ≤ 5·10⁴
  • s consists of English letters, digits, symbols, and spaces.

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.