From a9cb97282c0d0b3ae919dd300820bbdb16e3089e Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 27 Dec 2025 04:04:42 -0600 Subject: [PATCH] adding algo --- .../common_algos/two_sum_round_8.py | 16 ++++++++++++++ .../common_algos/valid_palindrome_round_8.py | 22 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_8.py create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_8.py diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_8.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_8.py new file mode 100644 index 00000000..6c0c6330 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_8.py @@ -0,0 +1,16 @@ +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 [] \ No newline at end of file diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_8.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_8.py new file mode 100644 index 00000000..4f7388ef --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_8.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): + + if s[i] != s[len_s - 1 - i]: + return False + + return True