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 firstname.lastname@example.org. 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.
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Sum of first K even-length Palindrome numbers
- Length of the longest substring that do not contain any palindrome
- Maximum even length sub-string that is permutation of a palindrome
- Binary String of given length that without a palindrome of size 3
- Check if string can be rearranged so that every Odd length Substring is Palindrome
- Total number of odd length palindrome sub-sequence around each centre
- Maximum length palindrome that can be created with characters in range L and R
- Length of longest palindrome list in a linked list using O(1) extra space
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Count all palindrome which is square of a palindrome
- Length of longest Palindromic Subsequence of even length with no two adjacent characters same
- N'th palindrome of K digits
- Palindrome Partitioning | DP-17
- Palindrome by swapping only one character