diff --git a/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_19.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_19.py new file mode 100644 index 00000000..6c0c6330 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/two_sum_round_19.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_19.py b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_19.py new file mode 100644 index 00000000..1ed43720 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/common_algos/valid_palindrome_round_19.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='[^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/top_150_questions_round_21/permutations.py b/src/my_project/interviews/top_150_questions_round_21/permutations.py new file mode 100644 index 00000000..a4632058 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_21/permutations.py @@ -0,0 +1,21 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def permute(self, nums: List[int]) -> List[List[int]]: + + final_answer = list() + + def back(answer = list()): + if len(answer) == len(nums): + final_answer.append(answer) + return + + for num in nums: + if num not in answer: + new_arr = answer + [num] + back(new_arr) + + back() + + return final_answer \ No newline at end of file diff --git a/tests/test_150_questions_round_21/test_permutations_round_21.py b/tests/test_150_questions_round_21/test_permutations_round_21.py new file mode 100644 index 00000000..95569315 --- /dev/null +++ b/tests/test_150_questions_round_21/test_permutations_round_21.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_21\ +.permutations import Solution + +class PermutationTestCase(unittest.TestCase): + + def test_permutation_1(self): + solution = Solution() + output = solution.permute(nums = [1,2,3]) + target = [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] + self.assertEqual(output, target) \ No newline at end of file