Ransom Note

Easy
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start•← → to step•? all shortcuts

Solution Guide: Ransom Note

Approach

Build a frequency map from magazine. Traverse ransomNote and decrement counts for needed letters. If any required letter count is unavailable, return false.

Complexity Analysis

Time
O(n + m)
Space
O(1)

Pattern

Frequency Count

Why It Works

Every ransom letter must consume one matching magazine letter. Frequency tracking enforces one-to-one usage.

Updated Mar 2026