You are given a string digits representing a non-negative integer, and an integer k.
Remove exactly k digits from digits, keeping the remaining digits in their original order, so that the resulting digit string, read as a number, is as small as possible. Strip any leading zeros from the result.
Return the resulting number as a string. If every digit is removed or the result would otherwise be empty, return "0".
Examples
Example 1
Input: digits = "1432219", k = 3
Output: "1219"
Explanation: Removing the digits 4, 3, and 2 leaves "1219", which is the smallest number reachable by removing exactly 3 digits.
Example 2
Input: digits = "10200", k = 1
Output: "200"
Explanation: Removing the leading 1 leaves "0200", which becomes "200" after stripping the leading zero.
Example 3
Input: digits = "10", k = 2
Output: "0"
Explanation: Removing both digits leaves nothing, so the result is "0".
Constraints
1≤k≤digits.length≤105
digits consists of only digits.
digits has no leading zeros, except when digits is exactly "0".
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run