Problema
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.
Vincoli
0 ≤ length ≤ 1,000
Esempi
Input:
text = "Never odd or even"
Output atteso:
expected = True
Input:
std::string text = "Never odd or even";
Output atteso:
bool expected = true;
Input:
string text = "Never odd or even";
Output atteso:
bool expected = true;
Spiegazione
Letters only, lowercased: "neveroddoreven" reads the same both ways.
Input:
text = "code"
Output atteso:
expected = False
Input:
std::string text = "code";
Output atteso:
bool expected = false;
Input:
string text = "code";
Output atteso:
bool expected = false;
Spiegazione
"c" and "e" differ, so it is not a palindrome.
Come affrontarlo
Prova prima da solo, poi apri un suggerimento alla volta.
Suggerimento 1
Skip non-letter and non-digit characters before comparing the ends.
Suggerimento 2
Compare the outer characters first, then recurse on the remaining middle part.
Suggerimento 3
Handle empty and single-character cleaned substrings as palindromes.
Complessità attesa
O(n) time, O(n) extra space
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.