Question DSA-STK-0065
HardWhat is the output of this code?
def remove_k(num, k):
st = []
for d in num:
while k and st and st[-1] > d:
st.pop(); k -= 1
st.append(d)
st = st[:len(st) - k] if k else st
return "".join(st).lstrip("0") or "0"
print(remove_k("1432219", 3), remove_k("10200", 1))
- A.
1229 200
- B.
1219 0200
- C.
Sign up free to see the answer and a step-by-step explanation.