Menu
CoddyTech

Longest Substring Without Repeating Characters

Look through a string for stretches of consecutive characters in which every character appears only once. In coddycode, the stretch ycode has five different characters, and no longer stretch avoids a repeat, so the answer is 5.

Checking every possible stretch works, but it is slow. A faster way keeps a window between two positions that never holds a repeat. Move the right edge one character at a time. When the new character is already inside the window, jump the left edge just past the place where that character was seen before. Remembering the last position of every character makes that jump instant, so the string is read only once.

Write a function named lengthOfLongestSubstring that gets a string s and returns the length of the longest substring (a run of consecutive characters) in which no character appears more than once.

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

Constraints: 1 <= s.length <= 5 * 10^4. s holds only English letters (lowercase and uppercase) and digits.

Function

lengthOfLongestSubstring(arg1: string) → integer
arg1string
Returnsinteger

Examples

Input
arg1 = "coddycode"
Output
5

lock icon+12 hidden tests on Submit

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

Case 1

Case 2

Case 3

Input

arg1 = "coddycode"

Expected

5