EvalFrame Technical Mock Interviews & Coding Practice

Ransom Note

Easy · Hash Table · Algorithm problem · all problems

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:** ```typescript canConstruct("a", "b") // false canConstruct("aa", "ab") // false canConstruct("aa", "aab") // true ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(m + n)
  • Space complexity: O(1)

Scanning magazine of length m and ransomNote of length n takes linear time O(m + n).

Follow-Up Questions Interviewers Ask About Ransom Note

  • How would you optimize if the character set is strictly lowercase English letters?
    Use a fixed-size integer array of length 26 instead of a hash table to avoid hash overhead and improve cache locality.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.