Keep the Digits, One of Each Letter
s holds digits and lowercase letters. Delete some of its letters so that every digit stays and every letter that occurs in s stays exactly once. The characters that remain keep their order.
Return the smallest possible result in plain string order, in which every digit comes before every letter.
Example 1
s "cbacdcbc"
returns "acdb"
There are no digits, so this keeps one copy of each letter, and acdb is the smallest way to do it.
Example 2
s "b1ab"
returns "1ab"
The digit must stay. Dropping the first b and keeping the last one gives 1ab, which is smaller than b1a.
Constraints
0 <= len(s) <= 60sholds digits and lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Largest Open PlotMedium
- Longest Balanced PieceMedium
- Longest Steady StretchMedium
- Most Pieces to Sort SeparatelyMedium
- Next Greater NodeMedium
- Plus Minus With ParenthesesMedium
- Remove Adjacent Duplicates in Groups of KMedium
- Remove K DigitsMedium