diff --git a/src/my_project/interviews/top_150_questions_round_11/ransome_note.py b/src/my_project/interviews/top_150_questions_round_11/ransome_note.py new file mode 100644 index 00000000..b581ce58 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_11/ransome_note.py @@ -0,0 +1,12 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def canConstruct(self,ransomNote: str, magazine: str) -> bool: + + for s in set(ransomNote): + + if ransomNote.count(s) > magazine.count(s): + return False + + return True \ No newline at end of file diff --git a/tests/test_150_questions_round_11/test_ransome_note_round_11.py b/tests/test_150_questions_round_11/test_ransome_note_round_11.py new file mode 100644 index 00000000..4505f7ec --- /dev/null +++ b/tests/test_150_questions_round_11/test_ransome_note_round_11.py @@ -0,0 +1,15 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_11\ +.ransome_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