Problem can be found in here!
Solution: Hash Table
def canConstruct(ransomNote: str, magazine: str) -> bool:
memo = defaultdict(int)
for char in magazine:
memo[char] += 1
for char in ransomNote:
if memo[char] == 0:
return False
memo[char] -= 1
return True
Time Complexity: , Space Complexity: , where n is the length of ransomNote and m is the length of magazine.