Decode String
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
1 <= len(s) <= 50- Letters are lowercase, brackets are balanced
- Every
[is preceded by its numberk
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.