402. Remove K Digits

Description

Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.

Constraints

  • 1 <= k <= num.length <= 105

  • num consists of only digits.

  • num does not have any leading zeros except for the zero itself.

Approach

Examples

Input: num = "1432219", k = 3

Output: "1219"

Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.

Solutions

Follow up

Last updated

Was this helpful?