Skip to content

Ransom Note

EasyArrays & Hashing
Decode it first. Clues, constraints, pattern and plan before any code.

You want to spell ransom_note using letters cut out of magazine. Each letter in magazine can be used only once. Return true if it can be done.

ransom_note = "a",  magazine = "b"     →  false
ransom_note = "aa", magazine = "ab"    →  false  (only one a)
ransom_note = "aa", magazine = "aab"   →  true

Constraints

  • 0 <= ransom_note.length, magazine.length <= 10^5
  • Both strings contain only lowercase English letters.