Ransom Note
Given two strings ransomNote and magazine, return true if ransomNote can be constructed using the letters from magazine, and false otherwise.
Each letter in magazine can only be used once in ransomNote.
Example 1
Input
a b
Output
false
Explanation
The magazine does not contain the character 'a', so the ransom note cannot be constructed.
Example 2
Input
aa ab
Output
false
Explanation
The magazine contains only one 'a', but the ransom note requires two.
Constraints
Hints:
Hint 1
Count the frequency of each character in the magazine.
Hint 2
Traverse the ransom note and decrease the corresponding character count. If any count becomes negative, the ransom note cannot be constructed.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 6, 2026
Last updated
Aug 6, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output