Given a number n as string, find the nth even-length positive palindrome number .
Input : n = "1" Output : 11 1st even-length palindrome is 11 . Input : n = "10" Output : 1001 The first 10 even-length palindrome numbers are 11, 22, 33, 44, 55, 66, 77, 88, 99 and 1001.
As, it is a even-length palindrome so its first half should be equal to second half and length will be 2, 4, 6, 8 …. To evaluate nth palindrome let’s just see 1st 10 even-length palindrome numbers 11, 22, 33, 44, 55, 66, 77, 88, 99 and 1001 . Here, nth palindrome is nn’ where n’ is reverse of n . Thus we just have to write n and n’ in a consecutive manner where n’ is reverse of n .
Below is implementation of this approach .
Time Complexity : O(n)
This article is contributed by Surya Priy. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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.
- Sum of first K even-length Palindrome numbers
- Maximum even length sub-string that is permutation of a palindrome
- Find Nth even length palindromic number formed using digits X and Y
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Length of longest Palindromic Subsequence of even length with no two adjacent characters same
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Count all palindrome which is square of a palindrome
- Check if a number with even number of digits is palindrome or not
- Check if a given string is Even-Odd Palindrome or not
- Length of longest palindrome list in a linked list using O(1) extra space
- Binary String of given length that without a palindrome of size 3
- Length of the longest substring that do not contain any palindrome
- Maximum length palindrome that can be created with characters in range L and R
- Total number of odd length palindrome sub-sequence around each centre
- Check if string can be rearranged so that every Odd length Substring is Palindrome
- Longest palindrome formed by concatenating and reordering strings of equal length
- Length of Longest Palindrome Substring
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Longest Even Length Substring such that Sum of First and Second Half is same
- Check if a string contains a palindromic sub-string of even length