#K89337. Remove K Digits
Remove K Digits
Remove K Digits
You are given a non-negative integer represented as a string s
and an integer k
. Your task is to remove exactly k
digits from s
so that the resulting number is the smallest possible in lexicographic order. After removing the digits, any leading zeros in the resulting number should be removed (if the result is an empty string, output "0").
Note: The removal of digits should preserve the order of the remaining digits. It is guaranteed that 0 ≤ k ≤ |s|
where |s|
is the length of the string.
Example:
- For
s = "1432219"
andk = 3
, removing three digits can yield "1219", which is the smallest possible result. - For
s = "10200"
andk = 1
, the output should be "200". - For
s = "10"
andk = 2
, the output should be "0" because removing all digits leads to an empty string.
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains the string s
, representing a non-negative integer. The second line contains an integer k
, which indicates the number of digits to remove.
outputFormat
Output to standard output (stdout) the lexicographically smallest string possible after removing exactly k
digits from s
. The result should not have any leading zeros (unless the answer is "0").## sample
1432219
3
1219