Remove Digits — Programming Interview Question

Mipsmonsta
Jan 4, 2021

Lintcode #693

Question Setup

Given a non-negative integer number represented as a string, remove k digits from the number so that the new number is the smallest possible. The given number does not contain any leading zero.

Solution Visualised

In Step 1, note that you have to remove the correct digits and there are different scenarios to handle depending on the values of the digits when enumerating through from left to right.

Also, remember to take care to return ‘0’ if all digits are removed due to k being at same length as the character length in the input number.

Python Code

Happy coding folks!

--

--

Mipsmonsta

Writing to soothe the soul, programming to achieve flow