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.
In my solution, I tried make the function work for big inputs too, so, I sorted before test and I dicide use bisect to improove the list comprehension time:
import bisect
# Complete the makeAnagram function below.
def makeAnagram(a, b):
a_s = sorted(a)
b_s = sorted(b)
if len(a_s) > len(b_s):
a_s, b_s = b_s, a_s
i = 0
while i < len(a_s):
n_i = a_s[i]
if n_i in b_s:
j = bisect.bisect_left(b_s, n_i)
del b_s[j]
j = bisect.bisect_left(a_s, n_i)
del a_s[j]
i -= 1
i += 1
total = len(a_s) + len(b_s)
return total
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 →
In my solution, I tried make the function work for big inputs too, so, I sorted before test and I dicide use bisect to improove the list comprehension time: