DSA · Hash Table · #141
Ransom Note
Module 54 · difficulty 2/5·⏱ 30:00starts on first keystroke
Given two strings `ransomNote` and `magazine`, return `true` if `ransomNote` can be constructed using the letters from `magazine`, and `false` otherwise. Each letter in `magazine` can be used **at most once**. Implement the function `canConstruct(ransomNote, magazine)`.
Examples
ransomNote = "a", magazine = "b"→falseransomNote = "aa", magazine = "ab"→false— Only one 'a' is available in the magazine.ransomNote = "aa", magazine = "aab"→true
Constraints
- · 1 <= ransomNote.length, magazine.length <= 10^5
- · ransomNote and magazine consist of lowercase English letters.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.