A string is just a piece of text — a row of characters like letters, numbers, or symbols. A palindrome is a special kind of text that reads the same way forward and backward.
Think of the word madam. Read it left to right: m-a-d-a-m. Now read it right to left: m-a-d-a-m. It is exactly the same. That makes madam a palindrome. The word hello is not, because reading it backward gives olleh, which is different.
You are given a string s. You must write a function that returns true if the string is a palindrome, and false if it is not.
bool palindromeChecker(string s) {
}
The function returns a bool, which is a value that is either true or false.
Real text often has capital letters, spaces, and punctuation. The problem asks us to ignore those. So before we check, we clean the string in two steps:
A and a count as the same letter. So Mom is treated like mom.a–z, A–Z, and 0–9. Spaces, commas, and other symbols are thrown away.After cleaning, we check if the leftover text reads the same forward and backward.
Example 1: Input is s = amannama. There is nothing to clean here — all letters, already lowercase. Read it forward: amannama. Read it backward: amannama. They match, so the output is true.
Example 2: Input is s = racecar. Forward it is racecar, and backward it is also racecar. So this is true as well.
A common, easy idea is the two-pointer method. Imagine putting one finger at the start of the cleaned string and another finger at the end. Compare the two characters they point to:
false right away.Keep going until your fingers meet in the middle. If you never found a mismatch, the string is a palindrome — return true.
This works because a palindrome must mirror itself: the first character must equal the last, the second must equal the second-to-last, and so on.