solve(s) — decode an encoded string. The rule is k[encoded]: the encoded text inside
the brackets is repeated exactly k times, and k is a positive integer that can have
several digits. Brackets can nest. The input is always valid (balanced brackets, digits
only as repeat counts).
Use a stack. Keep the text built so far (current) and the number being read (k). On [
push (current, k) and start fresh; on ] pop (previous, count) and setcurrent = previous + current.repeat(count).
Examples
solve("3[a]2[bc]") → "aaabcbc"
solve("3[a2[c]]") → "accaccacc"
solve("2[abc]3[cd]ef") → "abcabccdcdcdef"Sample tests