#K91472. Smallest Number
Smallest Number
Smallest Number
Given a non-negative integer represented as a string s
and an integer k
, remove exactly k digits from s
so that the resulting number is the smallest possible in lexicographical order. The resulting number should not contain unnecessary leading zeros (except if the result is exactly zero).
The problem can be formally described by the equation: Given a string \( s \) and an integer \( k \), find the lexicographically smallest string \( r \) obtained from \( s \) by removing exactly \( k \) characters.
inputFormat
The input consists of two lines:
- The first line contains the string
s
composed of digits. - The second line contains the integer
k
representing the number of digits to remove.
outputFormat
Output the smallest possible number (as a string) after removing exactly k
digits from s
. Ensure that the output does not contain any unnecessary leading zeros. If the result is empty, output 0
.
1432219
3
1219