You are given two strings of lowercase letters: a note and a magazine. You want to build the note by cutting individual letters out of the magazine. Each letter in the magazine may be used at most once.
Print YES if the note can be built (the magazine contains at least as many copies of every letter the note needs), otherwise print NO.
Line 1: the string note (lowercase letters, no spaces).
Line 2: the string magazine (lowercase letters, no spaces).
One line: YES or NO.
a-zExample 1
Input
abc aabbcc
Expected
YES
Explanation
The note needs one each of a, b, c; the magazine has two of each, so the note can be built: YES.
Example 2
Input
aabb ab
Expected
NO
Explanation
The note needs two a's and two b's, but the magazine has only one of each, so it cannot be built: NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →