Find the lexicographically largest palindromic Subsequence of a String | CPP program to find the largest palindromic subsequence ; Function to find the largest palindromic subsequence ; Find the largest character ; Append all occurrences of largest character to the resultant string ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string largestPalinSub ( string s ) { string res ; char mx = s [ 0 ] ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) mx = max ( mx , s [ i ] ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( s [ i ] == mx ) res += s [ i ] ; return res ; } int main ( ) { string s = " geeksforgeeks " ; cout << largestPalinSub ( s ) ; }