From df51a8c5d8497c51ade9be5cee0f64d8104a33a4 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 16 Jun 2026 04:51:57 -0600 Subject: [PATCH] adding updates --- .../common_algos/two_sum_round_1.py | 6 ++--- .../common_algos/two_sum_round_2.py | 21 +++++++++++++++++ .../common_algos/valid_palindrome_round_2.py | 23 +++++++++++++++++++ ...imum_adjacent_swapt_to_make_valid_array.py | 16 +++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_2.py create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_2.py create mode 100644 src/my_project/interviews/amazon_high_frequency_23/round_6/minimum_adjacent_swapt_to_make_valid_array.py diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_1.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_1.py index c7f907c0..581881df 100644 --- a/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_1.py +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_1.py @@ -10,12 +10,10 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: if v in answer: return [answer[v], k] - else: + else: answer[target - v] = k - - return [] - + return [] diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_2.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_2.py new file mode 100644 index 00000000..c7f907c0 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_2.py @@ -0,0 +1,21 @@ +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_2.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_2.py new file mode 100644 index 00000000..ea0a0cfc --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_2.py @@ -0,0 +1,23 @@ +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 + diff --git a/src/my_project/interviews/amazon_high_frequency_23/round_6/minimum_adjacent_swapt_to_make_valid_array.py b/src/my_project/interviews/amazon_high_frequency_23/round_6/minimum_adjacent_swapt_to_make_valid_array.py new file mode 100644 index 00000000..dbfff5bf --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_6/minimum_adjacent_swapt_to_make_valid_array.py @@ -0,0 +1,16 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def minimumSwaps(self, nums: List[int]) -> int: + + min_num = min(nums) + max_num = max(nums) + + id_min = nums.index(min_num) + + new_nums = [min_num] + nums[:id_min] + nums[id_min + 1:] + + id_max = new_nums[::-1].index(max_num) + + return id_min + id_max \ No newline at end of file