Problem 52
Ransom Note
Easy · 10 pts · String, Hash Table
Problem
You want to write a ransom note by cutting letters out of a magazine. You are given the text of the note and the text of the magazine. Each letter in the magazine can be used only once. Decide whether the note can be written. The note can be built exactly when, for every letter, the magazine contains at least as many copies of it as the note needs. Count the letters of the magazine, then go through the note and use up one count per letter.
Input
Two lines: the note and the magazine, both strings of lowercase letters.
Output
Print YES if the note can be built, otherwise NO.
Constraints
1 <= length of each string <= 100000
Example input
aa aab
Example output
YES
Explanation
The note "aa" needs two a's. The magazine "aab" has two a's (and a b that is not needed), so the note can be built: YES.