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.
Nice solution. Here's my javacript implementation of your solution.
functionmain(){vara=readLine();varb=readLine();//console.log(a);//console.log(b);varalphabet=[];// create an empty array for(vari=0;i<27;i++){// fill it with 27 0's, each representaing a number in the alphabet alphabet.push(0);};for(vari=0;i<a.length;i++){// increment alphabet array for all the letters in array 1varalphaIndex=a.charCodeAt(i)-"a".charCodeAt(0);alphabet[alphaIndex]+=1;};for(vari=0;i<b.length;i++){// decrement alphabet array for all the letters in array 2varalphaIndex=b.charCodeAt(i)-"a".charCodeAt(0);alphabet[alphaIndex]-=1;};vartally=0;// tally the results for(vari=0;i<alphabet.length;i++){tally+=Math.abs(alphabet[i]);}console.log(tally);}
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 →
Nice solution. Here's my javacript implementation of your solution.