You are given a string s of lowercase English letters.
A subsequence of s keeps some of its characters, in their original order, and drops the rest.
Return the lexicographically smallest subsequence of s that contains every distinct letter of s exactly once.
Examples
Example 1
Input: s = "bcabc"
Output: "abc"
Explanation: The distinct letters of s are a, b, c. Among all subsequences that use each of them exactly once, "abc" is the smallest in lexicographical order.
Example 2
Input: s = "cbacdcbc"
Output: "acdb"
Explanation: The distinct letters of s are a, b, c, d. Among all subsequences that use each of them exactly once, "acdb" is the smallest in lexicographical order.
Constraints
1≤s.length≤104
s consists of lowercase English letters.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up