A tiny templating language for generating test fixtures writes repeated text as k[text], meaning text written k times. Markers can be nested: 2[a3[b]] is abbbabbb.
Write expand(template) that returns the fully expanded string. Every number is followed by a [, every [ has a matching ], and letters outside markers are copied as they are.
Input: template = "2[x]3[yz]" Output: "xxyzyzyz"
xx followed by yzyzyz.
Input: template = "3[a2[c]]" Output: "accaccacc"
The inside a2[c] is acc, written 3 times.
0 <= template.length <= 301 <= k <= 30010^5 characters.template has lowercase letters, digits, [, and ].Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #253 Expand Repeat Markers. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.