#K41242. Lexicographical Subsequence Maximum Sum
Lexicographical Subsequence Maximum Sum
Lexicographical Subsequence Maximum Sum
Given a string S consisting of lowercase letters, your task is to find the lexicographically smallest subsequence of S that yields the maximum possible sum of alphabetical values of its characters.
Explanation: The maximum sum is achieved by selecting all instances of the letter with the highest alphabetical value in S. For example, if S = "acbd", the highest letter is 'd', and the only occurrence of 'd' is returned. Similarly, if S contains several occurrences of the maximum letter, such as S = "abababab", the answer is "bbbb" because 'b' is the maximum letter and it occurs four times.
Note: The input is provided via standard input (stdin) and the output must be produced on standard output (stdout).
inputFormat
The input consists of a single line containing a non-empty string S. The string S is composed solely of lowercase English letters.
Example Input:
acbd
outputFormat
Output the lexicographically smallest subsequence of S that has the maximum possible sum of alphabetical values of its characters. For the provided example, the answer is: d
.
acbd
d