diff --git a/src/my_project/interviews/amazon_high_frequency_23/round_2/two_sum_round_6.py b/src/my_project/interviews/amazon_high_frequency_23/round_2/two_sum_round_6.py new file mode 100644 index 00000000..6c0c6330 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_2/two_sum_round_6.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/round_2/valid_palindrome_round_8.py b/src/my_project/interviews/amazon_high_frequency_23/round_2/valid_palindrome_round_8.py new file mode 100644 index 00000000..07e7315e --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_2/valid_palindrome_round_8.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 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/valid_anagram.py b/src/my_project/interviews/top_150_questions_round_21/valid_anagram.py new file mode 100644 index 00000000..4bb079dc --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_21/valid_anagram.py @@ -0,0 +1,13 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + + lst_s = [c for c in s] + lst_t = [c for c in t] + + lst_s.sort() + lst_t.sort() + + return lst_s == lst_t \ No newline at end of file diff --git a/tests/test_150_questions_round_21/test_valid_anagram_round_21.py b/tests/test_150_questions_round_21/test_valid_anagram_round_21.py new file mode 100644 index 00000000..9912c342 --- /dev/null +++ b/tests/test_150_questions_round_21/test_valid_anagram_round_21.py @@ -0,0 +1,16 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_21\ +.valid_anagram import Solution + +class ValidAnagramTestCase(unittest.TestCase): + + def test_is_valid_anagram(self): + solution = Solution() + output = solution.isAnagram(s="anagram", t="nagaram") + self.assertTrue(output) + + + def test_is_no_valid_anagram(self): + solution = Solution() + output = solution.isAnagram(s="rat", t="car") + self.assertFalse(output) \ No newline at end of file