समस्या
Decide whether text is a palindrome, considering only letters and digits and ignoring case.
Implement is_palindrome(text).
Input
text: The text to check (ASCII characters).
Output
Return true for a palindrome, otherwise false.
सीमाएँ
0 ≤ length ≤ 10,000
उदाहरण
इनपुट:
text = "Racecar"
अपेक्षित आउटपुट:
expected = True
इनपुट:
std::string text = "Racecar";
अपेक्षित आउटपुट:
bool expected = true;
इनपुट:
string text = "Racecar";
अपेक्षित आउटपुट:
bool expected = true;
व्याख्या
Lowercased, "racecar" reads the same both ways.
इनपुट:
text = "hello"
अपेक्षित आउटपुट:
expected = False
इनपुट:
std::string text = "hello";
अपेक्षित आउटपुट:
bool expected = false;
इनपुट:
string text = "hello";
अपेक्षित आउटपुट:
bool expected = false;
व्याख्या
"hello" backwards is "olleh", which is different.
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Ignore anything that is not a letter or digit before comparing.
संकेत 2
Move inward from both ends, comparing case-insensitive characters.
संकेत 3
Skip punctuation and spaces carefully so they do not break valid palindromes.
अपेक्षित जटिलता
O(n) time, O(1) extra space
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।