Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Remove K Digits

XPChallenge Points: 20
levelLevel: Medium

You are given a numeric string and an integer k. Your task is to delete exactly k digits from the string so that the resulting number is the smallest possible.
The digits must remain in their original order, and the final result must not contain unnecessary leading zeroes.
If removing all digits results in an empty value, return "0".

Example 1:

Input: num = "7650281", k = 3

Output: "0281"

Explanation:

Removing digits '7', '6', and '5' makes the smallest result. After trimming leading zero, final answer is "281".

Example 2:

Input: num = "200111", k = 2

Output: "0111"

Explanation:

Remove the '2' and one '1', giving the smallest possible remaining number. After removing leading zero → "111".

Example 3:

Input: num = "9", k = 1

Output: "0"

Explanation:

Removing the only digit leaves nothing, so return "0".

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result