समस्या
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.
सीमाएँ
0 ≤ length of each ≤ 10,000 (ASCII)
उदाहरण
इनपुट:
first = "Listen"
second = "Silent"
अपेक्षित आउटपुट:
expected = True
इनपुट:
std::string first = "Listen";
std::string second = "Silent";
अपेक्षित आउटपुट:
bool expected = true;
इनपुट:
string first = "Listen";
string second = "Silent";
अपेक्षित आउटपुट:
bool expected = true;
व्याख्या
Both use e, i, l, n, s, t once each.
इनपुट:
first = "apple"
second = "paddle"
अपेक्षित आउटपुट:
expected = False
इनपुट:
std::string first = "apple";
std::string second = "paddle";
अपेक्षित आउटपुट:
bool expected = false;
इनपुट:
string first = "apple";
string second = "paddle";
अपेक्षित आउटपुट:
bool expected = false;
व्याख्या
The letters and counts differ.
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Remove non-letters and ignore case before comparing.
संकेत 2
Count character frequencies for both phrases, or sort their normalized forms.
संकेत 3
Punctuation and spaces should not affect the result.
अपेक्षित जटिलता
O(n) time, O(1) extra space
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।