Anagram Check

A word is anagram of another word if we can rearrange the letter to create that word.

For example: "spar" is anagram of "rasp".

To check the anagram we can use Counter:

def isAnagram(wordA, wordB):
	return Counter(wordA) == Counter(wordB)

Time complexity (from dict compare):

  • O(1)O(1) if has different length
  • O(n)O(n) if has same length