Blind 75
13 / 75Free practice

Longest Substring Without Repeating Characters

Medium · Sliding window

Jump to code

Return the length of the longest contiguous substring whose characters are all distinct.

Examples

Example 1

s = "abcabcbb"

Output: 3

Example 2

s = "bbbbb"

Output: 1

Constraints

  • 0 <= s.length <= 1000
  • s may consist of printable ASCII characters.
Need a hint?

When a duplicate arrives, jump past its last occurrence.

Asked in real interviews

Candidates reported versions of Longest Substring Without Repeating Characters from these company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 7 cases. A free account runs this problem; no XP needed.
Language
Case 1
Input
[
  "abcabcbb"
]
Expected
3
Case 2
Input
[
  "bbbbb"
]
Expected
1
Case 3
Input
[
  "pwwkew"
]
Expected
3
Case 4
Input
[
  ""
]
Expected
0
Case 5
Input
[
  "dvdf"
]
Expected
3

Drafts are saved per language in this browser when storage is available.