FunctionRacerProblemsRace

Flip and Double Brackets

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

s holds lowercase letters and two kinds of brackets, which are balanced and properly nested. Decode it from the innermost brackets outward:

The brackets disappear. Return the decoded string.

Example 1

s "a(bc)[d]"
returns "acbdd"

(bc) becomes cb and [d] becomes dd.

Example 2

s "(x[yz])"
returns "zyzyx"

[yz] becomes yzyz, and then the round brackets reverse xyzyz into zyzyx.

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