FastPrepRansom Note
Problems/Ransom Note

Ransom Note

The Walt Disney Company logoThe Walt Disney Company● EasyFULLTIMEOAPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interviewer asked: "Ransom Note (LeetCode 383)."

The report does not give input bounds or a letter alphabet. Here, both strings may be empty, use lowercase English letters, and have at most 20000 letters each.

The judged task matches the report at about 85%.

Given two strings, ransomNote and magazine, return true if the note can be made using letters from the magazine. Otherwise return false.

Each occurrence of a letter in magazine may be used once. Letters may be rearranged, and unused letters are allowed.

Function

canConstruct(ransomNote: String, magazine: String) → boolean

Examples

Example 1

ransomNote = "aa"magazine = "ab"return = false

The note needs two copies of a, but the magazine has only one. Return false.

Example 2

ransomNote = "aa"magazine = "aab"return = true

The two copies of a make the note. The unused b is allowed. Return true.

Constraints

  • 0 <= ransomNote.length <= 20000
  • 0 <= magazine.length <= 20000
  • Both strings contain only lowercase English letters.

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public boolean canConstruct(String ransomNote, String magazine) {
        // Write your code here
    }
}
Checking account…