Lexicographically largest sub | Function to return the lexicographically largest sub - sequence of s ; Get the max character from the string ; Use all the occurrences of the current maximum character ; Repeat the steps for the remaining string ; Driver code
function getSubSeq ( s , n ) { var res = " " ; var cr = 0 ; while ( cr < n ) { var mx = s [ cr ] . charCodeAt ( 0 ) ; for ( var i = cr + 1 ; i < n ; i ++ ) mx = Math . max ( mx , s [ i ] . charCodeAt ( 0 ) ) ; var lst = cr ; for ( var i = cr ; i < n ; i ++ ) if ( s [ i ] . charCodeAt ( 0 ) == mx ) { res += s [ i ] ; lst = i ; } cr = lst + 1 ; } return res ; } var s = " " ; var n = s . length ; document . write ( getSubSeq ( s , n ) ) ;