#C4765. Smallest Subsequence of Distinct Characters
Smallest Subsequence of Distinct Characters
Smallest Subsequence of Distinct Characters
Given a string (s), find the lexicographically smallest subsequence that contains every distinct character in (s) exactly once. The subsequence must maintain the relative order of characters from (s).
In other words, if (t) is the required subsequence, then (t) should be a subsequence of (s), contain all unique characters from (s) exactly once, and be the smallest in lexicographical order among all such subsequences.
For example, if (s = "bcabc"), then the answer is (abc); if (s = "cbacdcbc"), then the answer is (acdb).
inputFormat
The input consists of a single line containing the string (s) which is composed of lowercase English letters.
outputFormat
Output a single line containing the lexicographically smallest subsequence of (s) that contains every distinct character exactly once.## sample
bcabc
abc