Solution:
I.) Sort both the strings O(m log m) and then compare each of the sorted strings O(m) => O(m log m).
II.) Create an array of size 26, in which store the counts of each alphabet in A. As you process B, decrement the count. If any of the counts are not equal to 0, then it is NOT an anagram pair. => O(m)
http://www.geeksforgeeks.org/archives/18752
I.) Sort both the strings O(m log m) and then compare each of the sorted strings O(m) => O(m log m).
II.) Create an array of size 26, in which store the counts of each alphabet in A. As you process B, decrement the count. If any of the counts are not equal to 0, then it is NOT an anagram pair. => O(m)
http://www.geeksforgeeks.org/archives/18752
No comments:
Post a Comment