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.
def sherlockAndAnagrams(s):
combinations=[]
count=0
for i in range(1,len(s)+1):
for j in range(len(s)-i+1):
a = "".join(sorted(s[j:j+i]))
combinations.append(a)
for i,s in zip(combinations,range(len(combinations))):
for j in range(s+1,len(combinations)):
if(i == combinations[j]):
count+=1
return(count)
for i,s in zip(combinations,range(len(combinations))):
for j in range(s+1,len(combinations)):
if(i == combinations[j]):
count+=1
return(count)
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 →
we dont even need counter!
def sherlockAndAnagrams(s): combinations=[] count=0 for i in range(1,len(s)+1): for j in range(len(s)-i+1): a = "".join(sorted(s[j:j+i])) combinations.append(a)