Code RoomRemove k digits
MediumPrep Room Coding #1191

Remove k digits

CodingAlgorithms & data structuresMid–Senior~24 min

Given a string num representing a non-negative integer and an integer k, remove exactly k digits so the resulting number is the smallest possible. Return it as a string with no leading zeros (return '0' if the result is empty or all zeros). 1 <= len(num) <= 100000, 0 <= k <= len(num). Example: num='1432219', k=3 -> '1219'.

Implement
remove_k_digits(num: str, k: int) → str
Examples
in["1432219",3]out"1219"
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 24 min
InputExpectedGot
["1432219",3]"1219"not run yetsample