Flip and Double Brackets
s holds lowercase letters and two kinds of brackets, which are balanced and properly nested. Decode it from the innermost brackets outward:
(text)stands fortextwritten backwards.[text]stands fortextwritten twice.
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
0 <= len(s) <= 40sholds lowercase letters and the brackets()and[], balanced and properly nested- the decoded string has at most 200 characters
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.