diff --git a/src/my_project/interviews/amazon_high_frequency_23/round_2/two_sum_round_3.py b/src/my_project/interviews/amazon_high_frequency_23/round_2/two_sum_round_3.py new file mode 100644 index 00000000..534c7ec3 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_2/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/round_2/valid_palindrome_round_3.py b/src/my_project/interviews/amazon_high_frequency_23/round_2/valid_palindrome_round_3.py new file mode 100644 index 00000000..eaab0a37 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_2/valid_palindrome_round_3.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 it 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/ransom_note.py b/src/my_project/interviews/top_150_questions_round_21/ransom_note.py new file mode 100644 index 00000000..adb3bb13 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_21/ransom_note.py @@ -0,0 +1,11 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def canConstruct(self,ransomNote: str, magazine: str) -> bool: + + for c in set(ransomNote): + if ransomNote.count(c) > magazine.count(c): + return False + + return True \ No newline at end of file diff --git a/tests/test_150_questions_round_21/test_ransom_note_round_21.py b/tests/test_150_questions_round_21/test_ransom_note_round_21.py new file mode 100644 index 00000000..4e0c2b59 --- /dev/null +++ b/tests/test_150_questions_round_21/test_ransom_note_round_21.py @@ -0,0 +1,15 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_21\ +.ransom_note import Solution + +class RansomeNoteTestCase(unittest.TestCase): + + def test_is_ransome_note(self): + solution = Solution() + output = solution.canConstruct(ransomNote="aa", magazine="aab") + self.assertTrue(output) + + def test_is_no_ransome_note(self): + solution = Solution() + output = solution.canConstruct(ransomNote="a", magazine="b") + self.assertFalse(output) \ No newline at end of file