diff --git a/src/my_project/interviews/top_150_questions_round_20/ransome_note.py b/src/my_project/interviews/top_150_questions_round_20/ransome_note.py new file mode 100644 index 00000000..2d8d9028 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_20/ransome_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_20/test_ransome_note_round_20.py b/tests/test_150_questions_round_20/test_ransome_note_round_20.py new file mode 100644 index 00000000..3c48dfe4 --- /dev/null +++ b/tests/test_150_questions_round_20/test_ransome_note_round_20.py @@ -0,0 +1,15 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_20\ +.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