Problem
Two phrases are anagrams if they contain exactly the same letters the same number of times, ignoring case, spaces and punctuation.
Implement is_anagram(first, second).
Input
first: The first phrase. second: The second phrase.
Output
Return true if the phrases are anagrams.
Constraints
0 ≤ length of each ≤ 10,000 (ASCII)
Examples
Input:
first = "Listen"
second = "Silent"
Expected output:
expected = True
Input:
std::string first = "Listen";
std::string second = "Silent";
Expected output:
bool expected = true;
Input:
string first = "Listen";
string second = "Silent";
Expected output:
bool expected = true;
Explanation
Both use e, i, l, n, s, t once each.
Input:
first = "apple"
second = "paddle"
Expected output:
expected = False
Input:
std::string first = "apple";
std::string second = "paddle";
Expected output:
bool expected = false;
Input:
string first = "apple";
string second = "paddle";
Expected output:
bool expected = false;
Explanation
The letters and counts differ.
How to approach it
Try on your own first, then open one hint at a time.
Hint 1
Remove non-letters and ignore case before comparing.
Hint 2
Count character frequencies for both phrases, or sort their normalized forms.
Hint 3
Punctuation and spaces should not affect the result.
Expected complexity
O(n) time, O(1) extra space
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.