239. Remove K Digits

MediumStringString

Given a non-negative integer represented as a string num and an integer k, remove exactly k digits so the resulting number is the smallest possible. Return it as a string without leading zeros (return "0" if the result is empty). Input: '"num", k'.

Input: '"num", k'.

Output: Quoted string — the smallest number.

Examples

Example 1
Input: "1432219", 3
Output: "1219"
Explanation: Remove 4,3,2 -> 1219.
Example 2
Input: "10200", 1
Output: "200"
Explanation: Remove 1 -> 0200 -> 200.
Example 3
Input: "10", 2
Output: "0"
Explanation: Remove all -> 0.

Constraints

Asked by

AdobeDeloitteGoogleBloombergAmazonAccenture
Solve this problem in the editor →