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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Check if a given string is Even-Odd Palindrome or not
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum digits to be removed to make either all digits or alternating digits same
- Smallest even digits number not less than N
- Check if the sum of digits of N is palindrome
- To check a number is palindrome or not without using any extra space
- Check if number is palindrome or not in Octal
- Recursive program to check if number is palindrome or not
- Program to check the number is Palindrome or not
- Check if number is palindrome or not in base B
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Count all palindrome which is square of a palindrome
- Check linked list with a loop is palindrome or not
- Check if a doubly linked list of characters is palindrome or not
- Check if any anagram of a string is palindrome or not
- Program to check if an array is palindrome or not using Recursion
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.