We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functionmakeAnagram(a:string,b:string):number{// Write your code hereletdictA=newMap<string,number>();letdictB=newMap<string,number>();for(letchofa){if(dictA.has(ch)){dictA.set(ch,dictA.get(ch)+1)}else{dictA.set(ch,1)}}for(letchofb){if(dictB.has(ch)){dictB.set(ch,dictB.get(ch)+1)}else{dictB.set(ch,1)}}letdeleteDiff=0;dictA.forEach((v,k)=>{if(dictB.has(k)){deleteDiff+=Math.abs(v-dictB.get(k));}else{deleteDiff+=v}})dictB.forEach((v,k)=>{if(!dictA.has(k)){deleteDiff+=v;}})returndeleteDiff}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →