Ransom Note - Problem
Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.
Each letter in magazine can only be used once in ransomNote.
Input & Output
Example 1 — Basic Case
$
Input:
ransomNote = "a", magazine = "b"
›
Output:
false
💡 Note:
Magazine doesn't contain the letter 'a', so ransom note cannot be constructed
Example 2 — Sufficient Letters
$
Input:
ransomNote = "aa", magazine = "aab"
›
Output:
true
💡 Note:
Magazine contains 2 'a's and 1 'b', which is enough to construct "aa"
Example 3 — Insufficient Letters
$
Input:
ransomNote = "aab", magazine = "baa"
›
Output:
true
💡 Note:
Magazine has 2 'a's and 1 'b', exactly what we need for "aab"
Constraints
- 1 ≤ ransomNote.length, magazine.length ≤ 105
- ransomNote and magazine consist of lowercase English letters.
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code