FunctionRacerProblemsRace

Keep the Digits, One of Each Letter

MediumStacks and queuesPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems