Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Is An Anagram - Python Question

Challenges • Asked about 5 years ago by Alexander Volinski

Alexander Volinski Commented on Oct 10, 2019:

is_anagram('cinema', 'iceman') should return False - Mistake?
Should return True

Link to problem: Is An Anagram.

Devesh Kumar Singh Commented on Dec 23, 2019:

isanagram('Mary', 'Army') should return False according to the test but I see that the assert statement states
`assert is
anagram('Mary', 'Army') == True` when I test my code

Anonymous Commented on Apr 09, 2020:

There's a solution that can be run in a time complexity of O(n).

  1. Create a hashmap for the first string that contains the characters as keys, and the number of times they appear as the values. Then do the same for the second string where every time a character appears, decrement the value in the map. If a value drops to zero, remove the key from the map. At the end, if the map is empty, then the words are anagrams.