Apply Operations to Make String Empty
You are given a string s.
Consider performing the following operation until s becomes empty:
- For every alphabet character from
'a'to'z', remove the first occurrence of that character insif it exists.
Return the value of the string s right before applying the last operation.
Example 1
Input
s = "aabcbbca"Output
"ba"The operations eventually leave
"ba" immediately before the final operation makes the string empty.Example 2
Input
s = "abcd"Output
"abcd"All characters are removed in the only operation, so the string just before the last operation is
"abcd".Constraints
- 1 <= s.length <= 5 * 10^5
- s consists only of lowercase English letters.