![]() |
VOOZH | about |
Given a string . The task is to find the lexicographically largest subsequence of the string which is a palindrome.
Examples:
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:
ss
Complexity Analysis: