From e8e1f6739bea68205780ea55addc1f26eeca42b0 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 11 Apr 2026 04:36:56 -0600 Subject: [PATCH] adding updates --- .../common_algos/two_sum_round_6.py | 21 ++++++++++++++++++ .../common_algos/valid_palindrome_round_6.py | 22 +++++++++++++++++++ .../ex_127_plus_one.py | 19 ++++++++++++++++ .../ex_127_plus_one.ts | 10 +++++++++ .../test_127_plus_one_round_22.py | 19 ++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_6.py create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_6.py create mode 100644 src/my_project/interviews/top_150_questions_round_22/ex_127_plus_one.py create mode 100644 src/my_project/interviews_typescript/top_150_questions_round_1/ex_127_plus_one.ts create mode 100644 tests/test_150_questions_round_22/test_127_plus_one_round_22.py diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_6.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_6.py new file mode 100644 index 00000000..c7f907c0 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_6.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_6.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_6.py new file mode 100644 index 00000000..fa21021b --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_6.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 diff --git a/src/my_project/interviews/top_150_questions_round_22/ex_127_plus_one.py b/src/my_project/interviews/top_150_questions_round_22/ex_127_plus_one.py new file mode 100644 index 00000000..9fa085b1 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_22/ex_127_plus_one.py @@ -0,0 +1,19 @@ +from typing import List + +class Solution: + def plusOne(self, digits: List[int]) -> List[int]: + + len_digits = len(digits) + + for i in range(len_digits - 1, -1, -1): + + if digits[i] != 9: + digits[i] += 1 + break + else: + digits[i] = 0 + + if digits[0] == 0: + return [1] + digits + else: + return digits \ No newline at end of file diff --git a/src/my_project/interviews_typescript/top_150_questions_round_1/ex_127_plus_one.ts b/src/my_project/interviews_typescript/top_150_questions_round_1/ex_127_plus_one.ts new file mode 100644 index 00000000..b8fc0b8f --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_1/ex_127_plus_one.ts @@ -0,0 +1,10 @@ +function plusOne(digits: number[]): number[] { + for (let i = digits.length - 1; i >= 0; i--) { + if (digits[i] !== 9) { + digits[i]++; + return digits; + } + digits[i] = 0; + } + return [1, ...digits]; +}; \ No newline at end of file diff --git a/tests/test_150_questions_round_22/test_127_plus_one_round_22.py b/tests/test_150_questions_round_22/test_127_plus_one_round_22.py new file mode 100644 index 00000000..c6acbadb --- /dev/null +++ b/tests/test_150_questions_round_22/test_127_plus_one_round_22.py @@ -0,0 +1,19 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_22\ +.ex_127_plus_one import Solution + +class PlusOneTestCase(unittest.TestCase): + + def test_leading_one(self): + solution = Solution() + output = solution.plusOne(digits=[9]) + target = [1, 0] + for k, v in enumerate(target): + self.assertEqual(v, output[k]) + + def test_no_leading_one(self): + solution = Solution() + output = solution.plusOne(digits=[1, 2]) + target = [1, 3] + for k, v in enumerate(target): + self.assertEqual(v, output[k]) \ No newline at end of file