Description
Given a non-negative integer num represented as a string and integer k, remove k digits to make the smallest possible number.
Examples
Input:
num = "1432219", k = 3Output:
"1219"Explanation:
Remove 4,3,2.
Input:
num = "54321", k = 2Output:
"321"Explanation:
Remove the first two digits (5 and 4) since they are larger than the digits that follow them. This creates the smallest possible number by always removing larger digits when they appear before smaller ones.
Input:
num = "112", k = 1Output:
"11"Explanation:
Since the first two digits are the same (both 1s), removing the last digit (2) because it's larger than the preceding digits. This demonstrates the case where there are duplicate digits and need to remove from the end when earlier digits are not decreasing.
Constraints
- •
1 ≤ k ≤ num.length ≤ 10⁵