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 job. My implementation was similar, but I ended counted all values in counter which were greater than 1 during each iteration.
defsherlockAndAnagrams(s):counts=0foriinrange(len(s)):substrings=["".join(sorted(s[idx:idx+i+1]))foridxinrange(0,len(s))]counts+=sum([(v-1)*v// 2 for _,v in collections.Counter(substrings).items()])returncounts
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Anagrams
You are viewing a single comment's thread. Return to all comments →
Nice job. My implementation was similar, but I ended counted all values in counter which were greater than 1 during each iteration.