Loading...
Loading...
Loading...
A number is given as a string of digits. Remove exactly k digits so the remaining number is as small as possible. Print it without leading zeros. If nothing remains, print 0.
Example 1
Input
1432219 3
Output
1219
Example 2
Input
10200 1
Output
200
Try the problem first. Open one hint at a time.
A bigger digit in front of a smaller one should be removed.
Keep a stack. While the top is bigger than the new digit and you may still remove, pop it. At the end remove from the back.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor