Given string num representing a non-negative integer and an integer k, return the smallest possible integer after removing k digits from num.
Key Insight: To minimize the number, we want smaller digits at the front. Use a monotonic increasing stack: whenever we see a digit smaller than the stack top, pop larger digits (if we still have removals left).
Greedy Strategy:
Why this works: A larger digit followed by a smaller digit creates an opportunity - removing the larger digit shifts smaller digits left, reducing the overall number.
num = "1432219", k = 3"1219"num = "10200", k = 1"200"num = "10", k = 2"0"1 <= k <= num.length <= 10^5num consists of only digitsnum does not have any leading zeros except for the zero itselfClick "Run" to execute your code against test cases
Socratic guidance - I'll ask questions, not give answers