From c9556be7da72843c1d09bbbb6c86bc0f59d366fc Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 1 Oct 2025 04:27:18 -0600 Subject: [PATCH] adding algo --- .../top_150_questions_round_20/ransome_note.py | 11 +++++++++++ .../test_ransome_note_round_20.py | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_20/ransome_note.py create mode 100644 tests/test_150_questions_round_20/test_ransome_note_round_20.py 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