You are viewing a single comment's thread. Return to all comments →
JAVASCRIPT solution
function makeAnagram(a, b) { const [small, big] = a.length < b.length ? [a, b] : [b, a]; const map = new Map(); for (let c of small) { map.set(c, (map.get(c) ?? 0) + 1); } let remain = 0; for (let c of big) { !map.has(c) ? remain++ : map.set(c, map.get(c) - 1); } for (let [k, v] of map) { remain += v < 0 ? v * -1 : v; } return remain; }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
JAVASCRIPT solution