Given a string . Find a string , where B is a palindrome and A is a subsequence of B.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, “cotst” is a subsequence of “contest”.
A palindrome is a string that reads the same forward or backward.
Input : A = "aba" Output : B = aba Explanation : "aba" is a subsequence of "aba" which is a palindrome. Input : A = "ab" Output : B = abba
Approach: Let reverse(s) be the reverse of a string . Now, s + reverse(s) will always have as a subsequence (as first half) and it is a palindrome.
Therefore, B = A + reverse(A).
Below is the implementation of the above approach:
- Find the count of palindromic sub-string of a string in its sorted form
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Find all palindromic sub-strings of a given string | Set 2
- Find all distinct palindromic sub-strings of a given string
- Find the lexicographically largest palindromic Subsequence of a String
- Make palindromic string non-palindromic by rearranging its letters
- Check if a string contains a palindromic sub-string of even length
- Lexicographically first palindromic string
- Given a string, print all possible palindromic partitions
- Count All Palindromic Subsequence in a given String
- Count palindromic characteristics of a String
- Print all palindromic partitions of a string
- Number of strings of length N with no palindromic sub string
- Distinct palindromic sub-strings of the given string using Dynamic Programming
- Count pairs of non-overlapping palindromic sub-strings of the given string
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.