Design Gurus Logo
Problem 5: Ransom Note (easy)

Problem Statement

Given two strings, one representing a ransom note and the other representing the available letters from a magazine, determine if it's possible to construct the ransom note using only the letters from the magazine. Each letter from the magazine can be used only once.

Examples:

  1. Example 1:

    • Input: Ransom Note = "hello", Magazine = "hellworld"
    • Expected Output: true
    • Justification: The word "hello" can be constructed from the letters in "hellworld".
  2. Example 2:

    • Input: Ransom Note = "notes", Magazine = "stoned"
    • Expected Output: true
    • Justification: The word "notes" can be fully constructed from "stoned" from its first 5 letters.
  3. Example 3:

    • Input: Ransom Note = "apple", Magazine = "pale"
    • Expected Output: false
    • Justification: The word "apple" cannot be constructed from "pale" as we are missing one 'p'.

Constraints:

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

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory