You are viewing a single comment's thread. Return to all comments →
JS solution:
function makeAnagram(a, b) { let firstArr = [...a].sort() let secondArr = [...b].sort() let numDel = 0 let i = 0 while (i < firstArr.length) { const first = firstArr[i] const second = secondArr[i] if (first !== second) { numDel++ if (first > second) { secondArr.splice(i, 1) } else { firstArr.splice(i, 1) } } else { i++ } } if (firstArr.length !== secondArr.length) numDel += Math.abs(secondArr.length - firstArr.length) return numDel }
Seems like cookies are disabled on this browser, please enable them to open this website
Making Anagrams
You are viewing a single comment's thread. Return to all comments →
JS solution: