Problem
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.
Constraints
0 ≤ length ≤ 10,000
Examples
Input:
text = "Racecar"
Expected output:
expected = True
Input:
std::string text = "Racecar";
Expected output:
bool expected = true;
Input:
string text = "Racecar";
Expected output:
bool expected = true;
Explanation
Lowercased, "racecar" reads the same both ways.
Input:
text = "hello"
Expected output:
expected = False
Input:
std::string text = "hello";
Expected output:
bool expected = false;
Input:
string text = "hello";
Expected output:
bool expected = false;
Explanation
"hello" backwards is "olleh", which is different.
How to approach it
Try on your own first, then open one hint at a time.
Hint 1
Ignore anything that is not a letter or digit before comparing.
Hint 2
Move inward from both ends, comparing case-insensitive characters.
Hint 3
Skip punctuation and spaces carefully so they do not break valid palindromes.
Expected complexity
O(n) time, O(1) extra space
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.