From 9940bc58c25797ef8d507825943fc6afdc834cf0 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 14 Jun 2026 05:13:11 -0600 Subject: [PATCH] adding updates --- .../common_algos/two_sum_round_7.py | 17 +++++++++++++ .../common_algos/valid_palindrome_round_6.py | 4 +-- .../common_algos/valid_palindrome_round_7.py | 22 ++++++++++++++++ ...maximum_sum_distinct_subarrays_lenght_k.py | 25 +++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_7.py create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_7.py create mode 100644 src/my_project/interviews/amazon_high_frequency_23/round_6/maximum_sum_distinct_subarrays_lenght_k.py diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_7.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_7.py new file mode 100644 index 00000000..a3a7d986 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_7.py @@ -0,0 +1,17 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + + answer = dict() + + for k, v in enumerate(nums): + + if v in answer: + return [answer[v], k] + else: + answer[target - v] = k + + return [] + diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_6.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_6.py index 68520882..6784cb7c 100644 --- a/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_6.py +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_6.py @@ -17,6 +17,6 @@ def isPalindrome(self, s: str) -> bool: for i in range(len_s//2): if s[i] != s[len_s - 1 - i]: - return False + return False - return True \ No newline at end of file + return True \ No newline at end of file diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_7.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_7.py new file mode 100644 index 00000000..68520882 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_7.py @@ -0,0 +1,22 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod +import re + +class Solution: + def isPalindrome(self, s: str) -> bool: + + # To lowercase + s = s.lower() + + # Remove non-alphanumeric characters + s = re.sub(pattern=r'[^a-zA-Z0-9]', repl='', string=s) + + # Determine if s is palindrome or not + len_s = len(s) + + for i in range(len_s//2): + + if s[i] != s[len_s - 1 - i]: + return False + + return True \ No newline at end of file diff --git a/src/my_project/interviews/amazon_high_frequency_23/round_6/maximum_sum_distinct_subarrays_lenght_k.py b/src/my_project/interviews/amazon_high_frequency_23/round_6/maximum_sum_distinct_subarrays_lenght_k.py new file mode 100644 index 00000000..cd23a982 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_6/maximum_sum_distinct_subarrays_lenght_k.py @@ -0,0 +1,25 @@ +from typing import List, Union, Collection, Mapping, Optional + +class Solution: + def maximumSubarraySum(self, nums: List[int], k: int) -> int: + max_sum= 0 + current_sum = 0 + freq = {} + left = 0 + + for right in range(len(nums)): + current_sum += nums[right] + + freq[nums[right]] = freq.get(nums[right], 0) + 1 + + if right - left > k - 1: + freq[nums[left]] -= 1 + if freq[nums[left]] == 0: + del freq[nums[left]] + current_sum -= nums[left] + left += 1 + + if right - left == k - 1 and len(freq) == k: + max_sum = max(max_sum, current_sum) + + return max_sum