dsa · easy
Ransom Note
You want to build the string note by cutting letters out of magazine. Each character of magazine may be used at most once, and you may not rearrange across different letters (an a cannot stand in for a b). Return whether note can be assembled that way.
Example
note = "aab", magazine = "abba": magazine holds two as and two bs. The note wants two as and one b. Counts cover the demand → true.
note = "abc", magazine = "abb": the note wants a c that the magazine never provides → false.
note = "aa", magazine = "ab": only one a is available → false.
## Arguments - note — string you must assemble - magazine — pool of letters; each character may be used at most once
Constraints
1 <= note.length, magazine.length <= 10^5 note and magazine contain lowercase English letters Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: "aab" "abba" Expected: true
Example 2
Input: "abc" "abb" Expected: false
Example 3
Input: "aa" "ab" Expected: false