Given a string . The task is to find the lexicographically largest subsequence of the string which is a palindrome.
Input : str = "abrakadabra" Output : rr Input : str = "geeksforgeeks" Output : ss
The idea is to observe a character a is said to be lexicographically larger than a character b if it’s ASCII value is greater than that of b.
Since the string has to be palindromic, the string should contain the largest characters only, as if we place any other smaller character in between the first and last character then it will make the string lexicographically smaller.
To find the lexicographically largest subsequence, first find the largest characters in the given string and append all of its occurrences in the original string to form the resultant subsequence string.
Below is the implementation of the above approach:
Time Complexity: O(N), where N is the length of the string.
- Lexicographically first palindromic string
- Lexicographically largest subsequence such that every character occurs at least k times
- Count All Palindromic Subsequence in a given String
- Lexicographically largest sub-sequence of the given string
- Lexicographically largest string formed from the characters in range L and R
- 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 n-th lexicographically permutation of a string | Set 2
- Find a palindromic string B such that given String A is a subsequense of B
- Find all palindromic sub-strings of a given string | Set 2
- Find the lexicographically smallest string which satisfies the given condition
- Find all distinct palindromic sub-strings of a given string
- Find length of longest subsequence of one string which is substring of another string
- Find number of times a string occurs as a subsequence in given string
- Make palindromic string non-palindromic by rearranging its letters
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.