diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_4.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_4.py new file mode 100644 index 00000000..c04ad7c7 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_4.py @@ -0,0 +1,20 @@ +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_4.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_4.py new file mode 100644 index 00000000..013e283c --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_4.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/amazon_high_frequency_23/round_6/minimum_number_of_operations_to_turn_array_into_a_palindrom.py b/src/my_project/interviews/amazon_high_frequency_23/round_6/minimum_number_of_operations_to_turn_array_into_a_palindrom.py new file mode 100644 index 00000000..e695ccce --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_6/minimum_number_of_operations_to_turn_array_into_a_palindrom.py @@ -0,0 +1,31 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def minimumOperations(self, nums: List[int]) -> int: + + l, r = 0, len(nums) - 1 + ls = nums[l] + rs = nums[r] + answer = 0 + + while l < r: + + if ls == rs: + l += 1 + r -= 1 + ls = nums[l] + rs = nums[r] + elif ls < rs: + l += 1 + ls += nums[l] + answer += 1 + else: + r -= 1 + rs += nums[r] + answer += 1 + + return answer + + +