172. Remove K Digits
Challenge1000 ms256 MBSolved by 0%
Read a non-negative number as a string of digits, and an integer k. Remove
exactly k digits so the number that remains is as SMALL as possible, keeping the
remaining digits in their original order.
Print the result with no leading zeros. If nothing remains, print 0.
Constraints - The number has between 1 and 100000 digits. - `0 ≤ k ≤ length` - The input has no leading zeros unless it is exactly `0`.
Input
The first line contains the number as a string of digits.
The second line contains an integer k — exactly how many digits to remove.
Output
Print the smallest possible remaining number, with no leading zeros. Print 0 if nothing remains.
Input1432219
3
Output1219
Noteremoves three digits from the middle
Input10200
1
Output200
Noteproduces a LEADING ZERO that must be stripped
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution