Menu
CoddyTech

Longest Substring Without Repeating Characters

You get a string s. Find the longest substring, a run of characters that sit next to each other, in which no character appears twice, and return its length.

Uppercase and lowercase letters count as different characters, so a and A are not a repeat.

Function

lengthOfLongestSubstring(s: string) → integer
sstring
the string to search
Returnsinteger
the length of the longest substring with no repeated character

Constraints

  • 1 ≤ s.length ≤ 5 × 104
  • s holds only English letters (lowercase and uppercase) and digits.
  • Uppercase and lowercase letters are different characters.

Examples

Input
s = "coddycode"
Output
5
Explanation
ycode holds five different characters. Adding the d before it gives dycode, with d twice, and no other run of five or more avoids a repeat.
challenge icon

Follow-up

What would you change if s could hold any Unicode character instead of letters and digits?

Reset code
def lengthOfLongestSubstring(s):
    # Write code here

Test #1

Test #2

Test #3

Argument

s = "coddycode"

Expected Output

5