Decode String

Practice this coding question on Coding Gurukul.

Problem statement

A sign controller compresses repeated text by writing a repeat count before a bracketed fragment. Fragments may themselves contain compressed fragments, so expanding the display requires respecting nested bracket boundaries. Your task Decode the string using the rule k[fragment], which repeats the fully decoded fragment k times. Ordinary lowercase letters appear literally. Important details Counts may contain several digits and are always positive. Brackets are balanced, and digits occur only as repeat counts. Adjacent compressed or plain segments concatenate in order. Do not repeat the raw bracket syntax. Worked example The code 2[a3[b]] expands the inner fragment to abbb, then repeats it twice. The result is abbbabbb.

Input format

One encoded string.

Output format

Print the fully decoded string.

Constraints

1 <= encoded length <= 30; 1 <= repeat counts <= 300; decoded length <= 100000; letters a-z.

Sample input

2[a3[b]]

Sample output

abbbabbb

Sign in to run or submit a solution in C++, Java or Python.