Longest Substring Without Repeats

Given a string s, return the length of the longest substring (a run of consecutive characters) in which no character appears twice.

Constraints

  • 0 ≤ length of s ≤ 50,000
  • s has printable ASCII characters (letters, digits, symbols and spaces).

Example 1

Input
s = "abcabcbb"
Output
3
Why:

abc is the longest run without a repeat.

Example 2

Input
s = "bbbbb"
Output
1
Why:

Any single b.

Example 3

Input
s = "pwwkew"
Output
3
Why:

wke. pwke is not a substring: its letters are not next to each other in s.

Hints

    Was this a good challenge?

    Solved by
    0
    Submissions
    0
    Accepted
    –