Ransom Note
You get a note and a magazine. Find out whether the note can be put together from letters cut out of the magazine, if each letter of the magazine can be used only once. Our example: the note "hello" and the magazine "shelfloor" — yes, and s, f, r and one o are left over.
- input
ransomNote,magazine: strings.- returns
trueifransomNotecan be made of letters cut out ofmagazine, each letter ofmagazineused at most once; otherwisefalse.- constraints
- 0 ≤ ransomNote.length ≤ 2000
- 1 ≤ magazine.length ≤ 2000
- ransomNote, magazine: lowercase English letters
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} ransomNote
* @param {string} magazine
* @return {boolean}
*/
function canConstruct(ransomNote, magazine) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more hash map problems
- 1Two SumEasysolve
- 217Contains DuplicateEasysolve
- 242Valid AnagramEasysolve
- 169Majority ElementEasysolve
- 205Isomorphic StringsEasysolve
- 290Word PatternEasysolve
- 219Contains Duplicate IIEasysolve
- 49Group AnagramsMediumsolve
- 128Longest Consecutive SequenceMediumsolve
- 36Valid SudokuMediumsolve
- 138Copy List with Random PointerMediumsolve
- 149Max Points on a LineHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.