आसान 0 हल किए गए 0% स्वीकृति

Anagram Check

Check whether two phrases use the same letters.

आप क्या सीखेंगे

  • Normalize text by case and spaces
  • Compare letter counts or sorted letters
  • Choose between sorting and counting

समस्या

अनुवाद दिखाएँ

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)

उदाहरण

उदाहरण 1
इनपुट:
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.

उदाहरण 2
इनपुट:
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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।