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