Remove K Digits
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
1 <= len(num) <= 100 <= k <= len(num)- Digits only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Rotating Queue With CooldownMedium
- Round Robin Completion TimesMedium
- Score of ParenthesesMedium
- Self Time per FunctionMedium
- Simplify PathMedium
- Two Teams in a CircleMedium
- Visible to the RightMedium
- Atoms in a Hydrate FormulaHard