This question evaluates string parsing and manipulation skills, particularly handling nested repetition encodings and managing state when expanding bracketed substrings.
Implement a decoder for an encoded string where repetition is expressed with a number followed by a bracketed substring.
Rules:
k[substring]
means
substring
repeated
k
times.
k
is a positive integer.
Examples:
"3[a]2[bc]"
→ Output:
"aaabcbc"
"3[a2[c]]"
→ Output:
"accaccacc"
"2[ab3[c]]x"
→ Output:
"abcccabcccx"
Return the decoded string.