easyHash maps and sets target 15 min
Ransom note
You want to spell a message, note, with letters cut out of a magazine, given as the string magazine. A letter you cut out is gone after one use, so if the magazine has two e's, the note can use at most two e's. Return True if you can cut out a letter for every letter of note, and False if not.
Letters left over in the magazine are fine, and an empty note can always be spelled.
Example 1
Input
note = "cab", magazine = "abacus"OutputTrueThe magazine has a c, an a and a b to cut out. The second a, the u and the s are left over.
Example 2
Input
note = "tool", magazine = "lots"OutputFalseThe note needs two o's and the magazine has one.
Example 3
Input
note = "", magazine = "abc"OutputTrueAn empty note needs no letters.
Constraints
0 ≤ len(note), len(magazine) ≤ 105
Both strings hold only the lowercase letters a to z.
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.