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.
# Write your code here
start = time.time()
count=0
dict_a = {}
dict_b = {}
for i in a:
if i in dict_a:
dict_a[i]+=1
else:
dict_a[i]=1
for i in b:
if i in dict_b:
dict_b[i]+=1
else:
dict_b[i]=1
temp_list = list(dict_a.keys()).copy()
for i in temp_list:
if i in dict_b:
count += abs(dict_a[i]-dict_b[i])
dict_a.pop(i)
dict_b.pop(i)
else:
count+=dict_a[i]
dict_a.pop(i)
count=count+sum(dict_b.values())
print(f'total time: {time.time()-start:.8f}')
return count
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 →
my python solution -
def makeAnagram(a, b):