Skip to content
MediumStringsFree practice

Longest Substring Without Repeating Characters

Asked atamazongooglemicrosoftmetaadobe

01 · Problem

Given a string s, find the length of the longest substring without repeating characters.

A substring is a contiguous non-empty sequence of characters within a string.

02 · Examples

Example 01
Input
s = "abcabcbb"
Output
3

The longest substring without repeating characters is "abc" (indices 0-2), length 3.

Example 02
Input
s = "pwwkew"
Output
3

The longest substring without repeating characters is "wke" (indices 2-4) or "kew" (indices 3-5), length 3.

03 · Constraints

  • 010 <= s.length <= 5 * 104
  • 02s consists of English letters, digits, symbols and spaces.

04 · Optimal complexity

Time
O(n)
Space
O(min(n, m))
05 · Two ways to work on it

Practice it alone or rehearse it as an interview.

Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.