Check if Two Strings are Anagram of Each Other
Given two strings, our task is to check whether these strings are an anagram of
each other or not.
An Anagram of a string is a string that contains the same characters, the
order of characters can be different.
For example:
Input: s1 = "hackyourcode" s2 = "codehackyour"
Output: True
Input: s1 = "pythoniseasy" s2 = "pythonisawesome"
Output: False
The most common method to solve this problem is to sort strings, then compare
each character but this method takes O(NlogN) time to perform.
This problem can be solved efficiently O(N) using HashTable. Think about it!
Thank you so much for reading this article, if you like this question please share this with your friends who love programming. And if you have questions or feedback please drop a comment.
To solve more problems, please check out this article "Top 10 String Interview Questions".
All the Best!
Comments
Post a Comment