118. Smallest Value After Removals
Medium
Given the digit string numero, remove exactly k digits to obtain the smallest possible nonnegative value. Return that value as a decimal string without leading zeros; if no digits remain or the value is zero, return "0".
Example 1
Input: numero = "1432219", k = 3
Output: "1219"
Explanation: Removing the digits 4, 3, and 2 produces the smallest possible value.
Example 2
Input: numero = "10200", k = 1
Output: "200"
Explanation: Removing the digit 1 leaves "0200", whose representation without leading zeros is "200".
Example 3
Input: numero = "10", k = 2
Output: "0"
Explanation: All digits are removed.
Constraints
- 1 <= numero.length <= 10^5
- `numero` contains only digits from `0` to `9`.
- 0 <= k <= numero.length
StackGreedyStrings
Saved in this browser
Caso 1
numero =
"1432219"
k =
3
Expected =
"1219"
Caso 2
numero =
"10200"
k =
1
Expected =
"200"
Caso 3
numero =
"10"
k =
2
Expected =
"0"
Run checks these 3 cases. Submit runs all 13, including hidden ones.