Back to course home
0% completed
Vote For New Content
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>
num
consists of only digits.num
does not have any leading zeros except for the zero itself.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Try it yourself