From 1b9dc6544ec2f66d2d664d17b1c1137f3e83c08e Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 3 Jul 2026 05:12:09 -0600 Subject: [PATCH] adding updates --- ..._substring_without_repeating_characters.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/my_project/interviews/google_top_exercises/round_1/09_longest_substring_without_repeating_characters.py diff --git a/src/my_project/interviews/google_top_exercises/round_1/09_longest_substring_without_repeating_characters.py b/src/my_project/interviews/google_top_exercises/round_1/09_longest_substring_without_repeating_characters.py new file mode 100644 index 00000000..26efb51b --- /dev/null +++ b/src/my_project/interviews/google_top_exercises/round_1/09_longest_substring_without_repeating_characters.py @@ -0,0 +1,21 @@ +from typing import List + +class Solution: + def lengthOfLongestSubstring(self, s: str) -> int: + char_index = {} + left = 0 + max_length = 0 + + for right in range(len(s)): + # If character seen before and in current window + if s[right] in char_index and char_index[s[right]] >= left: + # Move left pointer past the last occurrence + left = char_index[s[right]] + 1 + + # Update last seen index of current character + char_index[s[right]] = right + + # Update max length + max_length = max(max_length, right - left + 1) + + return max_length \ No newline at end of file