Problema
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.
Restrições
0 ≤ length ≤ 10,000
Exemplos
Entrada:
text = "Racecar"
Saída esperada:
expected = True
Entrada:
std::string text = "Racecar";
Saída esperada:
bool expected = true;
Entrada:
string text = "Racecar";
Saída esperada:
bool expected = true;
Explicação
Lowercased, "racecar" reads the same both ways.
Entrada:
text = "hello"
Saída esperada:
expected = False
Entrada:
std::string text = "hello";
Saída esperada:
bool expected = false;
Entrada:
string text = "hello";
Saída esperada:
bool expected = false;
Explicação
"hello" backwards is "olleh", which is different.
Como abordar
Tente sozinho primeiro e depois abra uma dica de cada vez.
Dica 1
Ignore anything that is not a letter or digit before comparing.
Dica 2
Move inward from both ends, comparing case-insensitive characters.
Dica 3
Skip punctuation and spaces carefully so they do not break valid palindromes.
Complexidade esperada
O(n) time, O(1) extra space
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.