Note From Magazine Letters

EasyHash Map≈ 15 min

You want to write the note note by cutting letters out of the text magazine. Every letter you cut can be used once. Return true if the magazine has enough of every letter the note needs, and false if not.

Both strings hold only lowercase letters a–z. The letters can come from anywhere in the magazine, in any order.

Examples

text
note = "meet", magazine = "teeming"   →  true
note = "noon", magazine = "nominal"   →  false
note = "", magazine = "abc"           →  true
note = "cab", magazine = "abacus"     →  true

In the second example the note needs two os, and "nominal" has only one. An empty note needs nothing, so any magazine will do.

Constraints

  • Each string holds between 0 and 50,000 letters.
  • Aim for O(n) in the length of both strings together.
Sound off. Turn on for key clicks and a chime when the tests pass.Inline suggestions off. Recommended while you are learning. Turn on to complete words as you type.
Console
›Run to see what your code prints

Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.