Notes

Personal notes on various topics

View on GitHub

Ransom Note

Problem Statement

Given two strings ransomNote and magazine, determine if ransomNote can be constructed using the letters from magazine. Each letter in magazine can only be used once in constructing ransomNote.

Examples

Example 1
Input: ransomNote = "a", magazine = "b"
Output: false

Example 2
Input: ransomNote = "aa", magazine = "ab"
Output: false

Example 3
Input: ransomNote = "aa", magazine = "aab"
Output: true

Constraints

Code Template

class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:
        # Your code here
        pass

Solutions

Back to Problem List Back to Categories