Write a Python program to find the length of the longest substring without repeating characters in a given string
input_string = "abcabcbb"
char_index = {}
max_length = 0
start = 0
for end in range(len(input_string)):
if input_string[end] in char_index and char_index[input_string[end]] >= start:
start = char_index[input_string[end]] + 1
char_index[input_string[end]] = end
max_length = max(max_length, end - start + 1)
print("Length of the longest substring without repeating characters:", max_length)
Output:
Length of the longest substring without repeating characters: 3
If you are a beginner and want to know more about Python programming, you can read my Basics of Python blogs (From part 1 to part 15).
HAPPY LEARNING !!!