Are the two strings or phrases anagrams or not algorithm
First thing first, What is anagram?
Anagrams are phrases/words of which one can be created from the other with rearrangement of characters.
Examples of anagram strings:
Debit card and bad credit
George Bush and He Bugs Gore
Now, given two strings, how would do find if the strings are anagrams or not.
The approach I used is a follows:
1. remove the space out of the strings
2. compare the length of strings, if they don’t match, they ain’t anagrams
3. sort the characters of each string
4. check character by character and see if they match till the end
This is approach I used with
o(nlogn) because of the sorting part. All the others can be done in o(n)