Given a number N containing even number of digits. The task is to check whether that number is palindrome or not.
Input: N = 123321 Output: Palindrome Input: 1234 Output: Not palindrome
A Naive Approach is to traverse from front and back of that number and stop where they do not match.
An Efficient Approach is to use the below fact:
Palindrome Number having even number of digits is always divisible by 11.
Suppose the number is d1 d2 d3 d4…dn, whered1, d2, d3.. are digits of a number. If it is a palindrome then d1 = dn, d2 = dn-1, d3 = dn-2…..and so on. Now since divisibility of 11 states that the difference of sum of alternate digits of a number should be zero and same in the case of palindrome having even no. of digits i.e.
d1 + d3 + …+ dn-1 = d2 + d4 + d6 + … + dn
So, a palindromic number having even number of digits is always divisible by 11.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count the number of digits of palindrome numbers in an array
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Check if a number is Palindrome in PL/SQL
- Check if a number is Palindrome
- Check if the sum of digits of number is divisible by all of its digits
- Program to check the number is Palindrome or not
- Check if number is palindrome or not in Octal
- Recursive program to check if number is palindrome or not
- Generate number with given operation and check if it is palindrome
- Check if binary representation of a number is palindrome
- Bash program to check if the Number is a Palindrome
- Check whether the given floating point number is a palindrome
- To check a number is palindrome or not without using any extra space
- Check if actual binary representation of a number is palindrome
- Check if the sum of digits of N is palindrome
- Check if string remains palindrome after removing given number of characters
- Check if a number has digits in the given Order
- Check if the Xor of the frequency of all digits of a number N is zero or not
- Check if the sum of digits of a number N divides it
- Check if all digits of a number divide it
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.