Practice/Amazon/Leetcode 402. Remove K Digits
CodingMust
You are given a string representing a non-negative integer num and an integer k. Your task is to remove exactly k digits from the number so that the resulting number is as small as possible. The relative order of the remaining digits must be preserved.
Return the smallest possible number as a string. If all digits are removed, return "0".
k digits from the input string"0"Example 1:
Input: num = "1432219", k = 3 Output: "1219" Explanation: Remove the three digits 4, 3, and 2 (first occurrence) to form the new number 1219 which is the smallest.
Example 2:
Input: num = "10200", k = 1 Output: "200" Explanation: Remove the leading 1 and the result is 0200. After removing leading zeros, we get 200.
Example 3:
Input: num = "10", k = 2 Output: "0" Explanation: Remove all the digits from the number and it is left with nothing which is 0.
Example 4:
Input: num = "9", k = 1 Output: "0" Explanation: Removing the only digit leaves us with an empty result, which is represented as "0".