A string has been compressed with one rule: k[text] stands for text written out k times in a row. Groups can sit inside other groups. Expand s completely and return the result.
Letters outside any brackets are copied as they are. Digits only ever appear as a repeat count directly before a [, so there is no input like 4b or 3[7].
Expand from the inside out: 3[y] is yyy, so the group becomes 2[xyyy], which is xyyyxyyy. The trailing z follows once.
A count can have more than one digit: 10[o] is ten os.
Constraints
1 <= s.length <= 30s holds lowercase English letters, digits and the brackets [ ].s is a valid encoding: brackets are balanced, every [ comes right after its count, and no pair of brackets is empty.1 to 300, written without leading zeros.10⁵ characters long.A group can't be expanded until you reach its closing ], and the innermost group closes first: that last-opened, first-closed order is what a stack handles.
A group can't be written out until you know everything inside it, and the inside may hold groups of its own. So the innermost groups have to be expanded first, and the outer ones after them.
Time O(n + d · L)Space O(n + L)
The full walkthrough and code are part of Premium