Return the lexicographically smallest subsequence that contains every distinct character of the input string exactly once.
Smallest Subsequence of Distinct Characters
gfgGiven a string s, build a subsequence that:
s, exactly oncesA subsequence keeps the original relative order of characters, but you may remove any number of characters.
Choose characters so that every distinct letter appears once, while making the resulting string as small as possible in lexicographic order.
s consisting of lowercase English letters.1 <= s.length <= $10^{4}$s contains only lowercase English letterss exactly onceExample 1
Input
s = "bcabc"
Output
"abc"
Explanation
The distinct characters are {a, b, c}. Among all subsequences containing each once, "abc" is lexicographically smallest.
Example 2
Input
s = "cbacdcbc"
Output
"acdb"
Explanation
One valid subsequence is "acdb". It contains each distinct character exactly once and is lexicographically smaller than other valid choices such as "adbc".
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.