
Remove K Digits (hard)
Problem Statement
Given a non-negative integer represented as a string num and an integer k, delete k digits from num to obtain the smallest possible integer. Return this minimum possible integer as a string.
Examples
-
- Input:
num = "1432219", k = 3 - Output:
"1219" - Explanation: The digits removed are 4, 3, and 2 forming the new number 1219 which is the smallest.
- Input:
-
- Input:
num = "10200", k = 1 - Output:
"200" - Explanation: Removing the leading 1 forms the smallest number 200.
- Input:
-
- Input:
num = "1901042", k = 4 - Output:
"2" - Explanation: Removing 1, 9, 1, and 4 forms the number 2 which is the smallest possible. Constraints:
- Input:
- 1 <= k <= num.length <= 10<sup>5</sup>
numconsists of only digits.numdoes not have any leading zeros except for the zero itself.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory