number = "1924"
k = 2
stack = []
for digit in number:
while stack and k > 0 and stack[-1] < digit:
stack.pop()
k -= 1
stack.append(digit)
if k > 0:
stack = stack[:-k]
print("".join(stack))
To embed this project on your website, copy the following code and paste it into your website's HTML: