From c0006c47b52ee567b6401dec8dd0d6565713dec0 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 22 Jul 2025 04:30:47 -0600 Subject: [PATCH] adding algo --- .../top_150_questions_round_18/ransome_note.py | 11 +++++++++++ .../test_ransome_note_round_18.py | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_18/ransome_note.py create mode 100644 tests/test_150_questions_round_18/test_ransome_note_round_18.py diff --git a/src/my_project/interviews/top_150_questions_round_18/ransome_note.py b/src/my_project/interviews/top_150_questions_round_18/ransome_note.py new file mode 100644 index 00000000..2d8d9028 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_18/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_18/test_ransome_note_round_18.py b/tests/test_150_questions_round_18/test_ransome_note_round_18.py new file mode 100644 index 00000000..e21053d1 --- /dev/null +++ b/tests/test_150_questions_round_18/test_ransome_note_round_18.py @@ -0,0 +1,15 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_18\ +.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