Strings: Making Anagrams

  • + 0 comments

    Intuitive, Readable Python code: O(N) complexity.

    def makeAnagram(a, b):
        # Write your code here
        a_list = list(a)
        b_list = list(b)
        remove_b = 0
        for l in b_list: 
            if l in a_list: 
                a_list.remove(l)
            else:
                remove_b +=1 
        remove_a = len(a_list) # unmatched letters remained in this list
        return remove_a + remove_b