Skip to main content
LeetCode 383, Easy. Topics: Hash Table, String, Counting. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 11 parametrized pytest cases, and a playground notebook:

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.

Examples

Constraints

  • 1 <= ransomNote.length, magazine.length <= 10^5
  • ransomNote and magazine consist of lowercase English letters.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Grind 75, Grind, NeetCode All.
Last modified on August 25, 2026