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.
- 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
- Binary String of given length that without a palindrome of size 3
- Maximum even length sub-string that is permutation of a palindrome
- 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
- Maximum length palindrome that can be created with characters in range L and R
- Longest palindrome formed by concatenating and reordering strings of equal length
- 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
- Construct a string of length L such that each substring of length X has exactly Y distinct letters
- Palindrome Partitioning | DP-17
- N'th palindrome of K digits
- Next word that does not contain a palindrome and has characters from first k
- Palindrome by swapping only one character
- Check if a given string is Even-Odd Palindrome or not
- Next smallest prime palindrome