From db6f842883d24b9be23fb76059efa4595d7c61c4 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 22 Dec 2024 04:37:02 -0600 Subject: [PATCH 1/2] adding ransome note --- .../top_150_questions_round_12/ransome_note.py | 0 .../test_ransome_note_round_12.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_12/ransome_note.py create mode 100644 tests/test_150_questions_round_12/test_ransome_note_round_12.py diff --git a/src/my_project/interviews/top_150_questions_round_12/ransome_note.py b/src/my_project/interviews/top_150_questions_round_12/ransome_note.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_150_questions_round_12/test_ransome_note_round_12.py b/tests/test_150_questions_round_12/test_ransome_note_round_12.py new file mode 100644 index 00000000..26939ec9 --- /dev/null +++ b/tests/test_150_questions_round_12/test_ransome_note_round_12.py @@ -0,0 +1,15 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_12\ +.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 From 4f577f907766e3f318646fa7974b8d4bbc4f7fa3 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 22 Dec 2024 04:39:34 -0600 Subject: [PATCH 2/2] updating algo --- .../top_150_questions_round_12/ransome_note.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/my_project/interviews/top_150_questions_round_12/ransome_note.py b/src/my_project/interviews/top_150_questions_round_12/ransome_note.py index e69de29b..b581ce58 100644 --- a/src/my_project/interviews/top_150_questions_round_12/ransome_note.py +++ b/src/my_project/interviews/top_150_questions_round_12/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