Remove K Digits

Given a string num representing a non-negative integer and an integer k, return the smallest possible integer after removing k digits from num.

Example 1
Inputnum = "1432219", k = 3
Output"1219"
Remove the three digits 4, 3, and 2 to form the new number 1219, which is the smallest.
Example 2
Inputnum = "10200", k = 1
Output"200"
Remove the leading 1 and the number is 200; the output must not contain leading zeroes.

Constraints

  • 1 <= k <= num.length <= 10^5
  • num consists of only digits.
  • num does not have any leading zeros except for the zero itself.

Asked at 23 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate