Problem · String
Modify the String
Learn this problemProblem statement
Given a string input_str of length n, choose any character that occurs at least twice and delete any one occurrence. Repeat this until all remaining characters are distinct. Return the lexicographically maximum string that can be formed this way.
Function
getString(input_str: String) → String
Complete the function getString in the editor below.
getString has the following parameters:
- string
input_str: a string of lengthn
Returns
string: the result of the operations, as described
Examples
Example 1
input_str = "aabcb"return = "acb"The length of the string,
n = 5. Some of the strings that can be formed are:
- "acb" - delete the first occurrences of 'a' and 'b'
- "abc" - delete the first occurrence of 'a' and the second occurrence of 'b'
Constraints
input_strcontains only lowercase English letters1 ≤ n ≤ 10^5