402. Remove K Digits

Practice Remove K Digits for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

num is a non-negative integer written as a string. Remove exactly k digits so that the remaining number is as small as possible, and return it as a string without leading zeros (return "0" if nothing or only zeros remain).

Example

num = "1432219", k = 3  ->  "1219"
num = "10200",   k = 1  ->  "200"
num = "10",      k = 2  ->  "0"

Constraints