FunctionRacerProblemsRace

Decode String

MediumStacks and queuesPython, JavaScript, TypeScript, Java, C++

The string s uses the encoding rule k[text]: the text inside the brackets is repeated exactly k times, and k is a positive whole number. Rules can be nested inside each other. Letters outside any bracket are copied as they are.

Return the decoded string.

Example 1

s "3[a]2[bc]"
returns "aaabcbc"

aaa then bcbc.

Example 2

s "2[a2[b]]"
returns "abbabb"

Inner part gives abb, repeated twice.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems