Longest Substring Without Repeating Characters

medium

Find the length of the longest substring without repeating characters

Longest Substring Without Repeating Characters

Key Insight

Expand right to add characters. On duplicate, jump left past last occurrence

Step 1Start Window
Window: 'a'Length: 1
L
R
a
0
b
1
c
2
a
3
b
4
c
5
b
6
b
7
[———]window

Begin with a single character window at the start.

1 / 5
Practice the Code

Step-by-Step Walkthrough: Longest Substring Without Repeating Characters

Expand right to add characters. On duplicate, jump left past last occurrence

  1. Start Window

    Begin with a single character window at the start.

  2. Expand Window

    Expand right while all characters are unique.

  3. Duplicate Found: 'a'

    Character 'a' at index 3 was already seen at index 0.

  4. Window After Jump

    Left jumps past the duplicate. Window is now valid again.

  5. Result

    The longest substring without repeating characters has length 3.