Level
Find the error
-
def length_of_longest_substring(s):
-
    char_index = {}
-
    max_length = start = 0
-
    for i, char in enumerate(s):
-
        if char in char_index:
-
            start = char_index[char] + 1
-
        char_index[char] = i
-
        max_length = max(max_length, i - start + 1)
-
    return max_length
-
print(length_of_longest_substring('abcabcbb'))

LeetCode 3: Longest Substring Without Repeating Characters

In this LeetCode-style problem, you need to find the length of the longest substring without repeating characters. Identify the line with a logical error and select the correct implementation to fix it. Pay attention to how the 'start' variable is updated and how it affects the calculation of substring length.