Remove K Digits

Medium · Stack & Monotonic Stack · about 20 minutes

Asked at Google, Amazon, Microsoft.

Given a non-negative integer written as a string num and an integer k, remove exactly k digits so the remaining number is as small as possible. Return it as a string without leading zeros ("0" if nothing is left).

Related guides