beads lists them from left to right.
A jeweler wants to take beads off so that exactly one bead of every color present remains. Beads cannot be rearranged: the ones left keep their original order.
Among all possible results, return the lexicographically smallest string.beads="dbdab" → 'bda'
The colors are a, b and d. Starting with a is impossible, since no d follows the only a. Starting with b (position 1) works, followed by d (position 2) and a, which gives bda.
beads="zyxzyx" → 'xzy'
We can start with the first x (position 2), since a z and a y still follow it. That gives xzy.
beads="mmm" → 'm'
beads consists of lowercase English lettersbeads="dbdab"
'bda'
Run checks the first 3 tests in your browser. Submit checks all 126 tests on the server, hidden ones included.