You are viewing a single comment's thread. Return to all comments →
Javascript solution
function makeFreqMap(str) { const map = {}; for (let char of str) { map[char] = map[char] + 1 || 1; } return map; } function checkMagazine(magazine, note) { const magMap = makeFreqMap(magazine); for (let word of note) { if (!magMap[word]) { console.log('No'); return; } magMap[word]--; } console.log('Yes'); }
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
Javascript solution