FastPrepFastPrep
Problem Brief

Modify the String

OA

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 Description

Complete the function getString in the editor below.

getString has the following parameters:

  • string input_str: a string of length n

Returns

string: the result of the operations, as described

1Example 1

Input
input_str = "aabcb"
Output
"acb"
Explanation
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'
It can be proven that the lexicographically maximum string that can be obtained is "acb".

Constraints

Limits and guarantees your solution can rely on.

  • input_str contains only lowercase English letters
  • 1 ≤ n ≤ 10^5
public String getString(String input_str) {
  // write your code here
}
Input

input_str

"aabcb"

Output

"acb"

Sign in to submit your solution.