#3816
Lexicographically Smallest String After Deleting Duplicate Characters
hard · 19.4% accepted · 41 likes · top 1%
hash table · string · stack · greedy · monotonic stack
Description
You are given a string s that consists of lowercase English letters.
You can perform the following operation any number of times (possibly zero times):
- Choose any letter that appears at least twice in the current string s and delete any one occurrence.
Return the lexicographically smallest resulting string that can be formed this way.
Solution