A coupon system shortens numeric codes by deleting exactly k digits, and it wants the resulting number to be as small as possible. The remaining digits keep their order.
Write dropDigits(code, k) where code is a string of digits. Return the smallest possible result as a string without leading zeros. If nothing is left, or only zeros are left, return "0".
Input: code = "1432219", k = 3 Output: "1219"
Dropping 4, 3, and one 2 leaves 1219, the smallest choice.
Input: code = "10200", k = 1 Output: "200"
Dropping 1 leaves 0200, which is 200 without leading zeros.
1 <= k <= code.length <= 10^5code has only digits and no leading zeros, except "0" itself.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 #267 Smallest Code After Dropping 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.