FunctionRacerProblemsRace

Remove K Digits

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

num is a string of digits. Delete exactly k digits so that the number left is as small as possible. Return it as a string with no leading zeros; if nothing is left or only zeros are left, return "0".

Example 1

num "1432219"
k 3
returns "1219"

Removing 4, 3, 2 leaves 1219.

Example 2

num "10200"
k 1
returns "200"

Remove the 1 to get 0200, which is 200.

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