19. Remove K Digits
β GFG solution to the Remove K Digits problem: find the smallest possible number after removing k digits using greedy monotonic stack approach. π
π§© Problem Description
π Examples
Example 1
Input: s = "4325043", k = 3
Output: "2043"
Explanation: Remove the three digits 4, 3, and 5 to form the new number "2043"
which is smallest among all possible removals.Example 2
Input: s = "765028321", k = 5
Output: "221"
Explanation: Remove the five digits 7, 6, 5, 8 and 3 to form the new number "0221".
Since we are not supposed to keep leading 0s, we get "221".π Constraints
β
My Approach
Greedy Monotonic Stack Strategy
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated