मध्यम 0 हल किए गए 0% स्वीकृति

Recursive Palindrome

Check a palindrome recursively, ignoring case and punctuation.

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

  • Check palindromes recursively
  • Ignore case and punctuation
  • Shrink the problem from both ends

समस्या

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

Decide whether text reads the same forwards and backwards, considering only letters and digits and ignoring case. Solve it recursively: compare the outer characters, then check the inside.

Implement is_palindrome_recursive(text).

Input

text: The text to check (ASCII characters).

Output

Return true for a palindrome, otherwise false.

सीमाएँ

0 ≤ length ≤ 1,000

उदाहरण

उदाहरण 1
इनपुट:
text = "Never odd or even"

अपेक्षित आउटपुट:
expected = True
इनपुट:
std::string text = "Never odd or even";

अपेक्षित आउटपुट:
bool expected = true;
इनपुट:
string text = "Never odd or even";

अपेक्षित आउटपुट:
bool expected = true;

व्याख्या

Letters only, lowercased: "neveroddoreven" reads the same both ways.

उदाहरण 2
इनपुट:
text = "code"

अपेक्षित आउटपुट:
expected = False
इनपुट:
std::string text = "code";

अपेक्षित आउटपुट:
bool expected = false;
इनपुट:
string text = "code";

अपेक्षित आउटपुट:
bool expected = false;

व्याख्या

"c" and "e" differ, so it is not a palindrome.

कैसे हल करें

पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।

संकेत 1

Skip non-letter and non-digit characters before comparing the ends.

संकेत 2

Compare the outer characters first, then recurse on the remaining middle part.

संकेत 3

Handle empty and single-character cleaned substrings as palindromes.

अपेक्षित जटिलता

O(n) time, O(n) extra space

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

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

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

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