Making anagrams solution

Problem Statement

Link to problem statement

Lessons learned

  • Use python built-in libraries like collections.Counter (very useful tool)
  • Brute force a problem on paper first with a small example

Solution

def makeAnagram(a, b):
    from collections import Counter
    counter_a = Counter(a)
    counter_b = Counter(b)
    counter_a.subtract(counter_b)
    return sum(abs(i) for i in counter_a.values())