Given a string `s`, remove duplicate letters so that every letter appears once and only once. Among all possible results, return the one that is smallest in lexicographical order. The letters you keep must stay in their original relative order.
Given a string s, remove duplicate letters so that every letter appears once and only once. Among all possible results, return the one that is smallest in lexicographical order. The letters you keep must stay in their original relative order.
Example 1:
Input: {"s":"bcabc"}
Output: abc
Constraints:
1≤s.length≤104
s consists of lowercase English letters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"s":"bcabc"}
s (5 letters)
underlined = last copy of that letter
b
0
c
1
a
2
b
3
c
4
First record where each letter appears for the last time (a→2, b→3, c→4). A letter can only be put off while a later copy exists.