What is a Palindrome String?
A string is called a palindrome if the reverse of the string is the same as the original one. For example, “madam”, “racecar”, “12321”.
Properties of a Palindrome:
A palindrome string has some properties which are mentioned below:
- A palindrome string has a symmetric structure which means that the character in the first half of the string are the same as in the rear half but in reverse order.
- Any string of length 1 is always a palindrome.
How to identify a Palindrome?
We can follow the below steps to identify a palindrome:
- Depending on the case sensitivity, either turn all the characters to lowercase or uppercase or keep them as it is.
- Now, Compare the first and the last character. If they are the same move to the second and second last and so on.
- If all the pairs of characters match, then it is a palindrome, otherwise not.
Some practice problems on Palindrome: