Mark As Completed Discussion

One Pager Cheat Sheet

  • Write a method isAnagram(str1, str2) to check if two strings are anagrams of each other, given that they contain only alphanumeric characters and have a length of up to 100000, with an expected time and space complexity of O(nlogn) and O(n), respectively.
  • We can use lowercase and sorting to efficiently determine if two strings, such as Mary and Army, are anagrams.
  • By splitting, sorting and joining the characters in each string, we can easily compare the raw characters present to determine if two strings are anagrams.
  • This algorithm has an O(n log n) time complexity and O(n) space complexity.

This is our final solution.

To visualize the solution and step through the below code, click Visualize the Solution on the right-side menu or the VISUALIZE button in Interactive Mode.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

That's all we've got! Let's move on to the next tutorial.

If you had any problems with this tutorial, check out the main forum thread here.