A coupon generator creates codes from a string of digits digits, then shortens each code by deleting exactly k digits. The remaining digits keep their order, and the shortest-looking code wins: it should be the smallest number possible.
Write smallestAfterRemoving(digits, k) that returns the smallest number, as a string, after removing k digits. Drop leading zeros from the answer, and return "0" if nothing (or only zeros) is left.
Input: digits = "1432219", k = 3 Output: "1219"
Remove 4, 3, and one 2 to get 1219.
Input: digits = "10200", k = 1 Output: "200"
Removing the 1 leaves 0200, which is 200.
1 <= k <= digits.length <= 100000digits contains only 0-9 and has no leading zeros unless it is "0".Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #575 Smallest Number After Removing Digits. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.