From 1732a6edce4a0416c3c9617b848d9fde0eab82b9 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 24 Jun 2026 05:02:57 -0600 Subject: [PATCH] adding updates --- .../common_algos/two_sum_round_3.py | 16 +++++++++ .../common_algos/valid_palindrome_round_3.py | 22 +++++++++++++ .../round_2/sample.py | 33 ------------------- .../round_3/sample.py | 33 ------------------- .../round_6/the_kth_factor.py | 21 ++++++++++++ 5 files changed, 59 insertions(+), 66 deletions(-) create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_3.py create mode 100644 src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_3.py delete mode 100644 src/my_project/interviews/amazon_high_frequency_23/round_2/sample.py delete mode 100644 src/my_project/interviews/amazon_high_frequency_23/round_3/sample.py create mode 100644 src/my_project/interviews/amazon_high_frequency_23/round_6/the_kth_factor.py diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_3.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_3.py new file mode 100644 index 00000000..2d8643f2 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_3.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_3.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_3.py new file mode 100644 index 00000000..68520882 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_3.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_2/sample.py b/src/my_project/interviews/amazon_high_frequency_23/round_2/sample.py deleted file mode 100644 index 0945d4ea..00000000 --- a/src/my_project/interviews/amazon_high_frequency_23/round_2/sample.py +++ /dev/null @@ -1,33 +0,0 @@ -from typing import List, Union, Collection, Mapping, Optional - -class Solution: - def jump(self, nums: List[int]) -> int: - """ - Greedy approach: At each position, jump to the farthest reachable index - - Example: [2,3,1,1,4] - - From index 0 (value=2): can reach indices 1,2 - - Greedy choice: Jump to index 1 (value=3) because it reaches farthest - - From index 1: can reach indices 2,3,4 (end) - - Answer: 2 jumps - """ - - if len(nums) <= 1: - return 0 - - jumps = 0 - current_end = 0 # End of current jump range - farthest = 0 # The farthest position we can reach - - for i in range(len(nums) - 1): - # Update farthest position reachable - farthest = max(farthest, i + nums[i]) - - # If we've reached the end of current jump range - if i == current_end: - jumps += 1 - current_end = farthest # Make the greedy choice - - if current_end > len(nums) - 1: - break - return jumps \ No newline at end of file diff --git a/src/my_project/interviews/amazon_high_frequency_23/round_3/sample.py b/src/my_project/interviews/amazon_high_frequency_23/round_3/sample.py deleted file mode 100644 index fa308366..00000000 --- a/src/my_project/interviews/amazon_high_frequency_23/round_3/sample.py +++ /dev/null @@ -1,33 +0,0 @@ -from typing import List, Union, Collection, Mapping, Optional - -class Solution: - def jump(self, nums: List[int]) -> int: - """ - Greedy approach: At each position, jump to the farthest reachable index - - Example: [2,3,1,1,4] - - From index 0 (value=2): can reach indices 1,2 - - Greedy choice: Jump to index 1 (value=3) because it reaches farthest - - From index 1: can reach indices 2,3,4 (end) - - Answer: 2 jumps - """ - - if len(nums) <= 1: - return 0 - - jumps = 0 - current_end = 0 # End of current jump range - farthest = 0 # The farthest position we can reach - - for i in range(len(nums) - 1): - # Update farthest position reachable - farthest = max(farthest, i + nums[i]) - - # If we've reached the end of current jump range - if i == current_end: - jumps += 1 - current_end = farthest # Make the greedy choice - - if current_end >= len(nums) - 1: - break - return jumps \ No newline at end of file diff --git a/src/my_project/interviews/amazon_high_frequency_23/round_6/the_kth_factor.py b/src/my_project/interviews/amazon_high_frequency_23/round_6/the_kth_factor.py new file mode 100644 index 00000000..8f618b9d --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_6/the_kth_factor.py @@ -0,0 +1,21 @@ +class Solution: + def kthFactor(self, n, k): + """ + :type n: int + :type k: int + :rtype: int + """ + + for i in range(1, n+1): + + if n % i == 0: + k -= 1 + + if k == 0: + return i + + return -1 + + + +