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.
I found your solution to be the most elegant. Here is in Javascript:
functionsherlockAndAnagrams(s){letcount=0;// Size of our sliding windowfor(leti=1;i<s.length;i++){letfound={};// Starting index of our sliding windowfor(letj=0;j+i<=s.length;j++){letsubstr=s.substr(j,i);substr=substr.split('').sort().join('');if(found[substr]){count+=found[substr];found[substr]++;}else{found[substr]=1;}}}returncount;}
Sherlock and Anagrams
You are viewing a single comment's thread. Return to all comments →
I found your solution to be the most elegant. Here is in Javascript: