Question DSA-STR-0064
HardWhat is the output of this code?
def decode(s):
stack, cur, k = [], "", 0
for c in s:
if c.isdigit():
k = k * 10 + int(c)
elif c == "[":
stack.append((cur, k)); cur, k = "", 0
elif c == "]":
prev, m = stack.pop(); cur = prev + cur * m
else:
cur += c
return cur
print(decode("2[a3[bc]]x"))
- A.
2abcbcbcx
- B.
abcabcx
- C.
abcbcbcx
- D.
abcbcbcabcbcbcx
Sign up free to see the answer and a step-by-step explanation.