Ransom Note

Given two strings ransomNote and magazine, return true if ransomNote can be built from the letters of magazine, and false otherwise. Each letter in magazine can be used at most once in ransomNote.

30:00

Ransom Note
easy
Free written solution
Topics
Companies

Given two strings ransomNote and magazine, return true if ransomNote can be built from the letters of magazine, and false otherwise. Each letter in magazine can be used at most once in ransomNote.

Example 1:
Input: {"ransomNote":"a","magazine":"b"}
Output: false
Constraints:
  • 1≤ransomNote.length,magazine.length≤1051 \leq \text{ransomNote.length}, \text{magazine.length} \leq 10^5

  • ransomNote and magazine consist of lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"ransomNote":"a","magazine":"b"}

Goal: cut the 1-letter note "a" out of the magazine "b", using each magazine letter at most once.

magazine (1 letters)

b

letter bins (counts)

a

0

b

0

ransom note (0/1 glued)

a
Variables
VariableValue
ransomNotea
magazineb
DepthFunction Call
Stack empty
0/6