Medium · Stacks & Queues

Decode String

Given a valid encoded string s of lowercase letters, digits and square brackets, where k[text] stands for text repeated k times (k ≥ 1, groups may nest), return the decoded string.

Examples

Example 1

{
  "s": "3[a2[c]]"
}

Output: "accaccacc"

Example 2

{
  "s": "2[abc]3[cd]ef"
}

Output: "abcabccdcdcdef"

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Stacks & Queues problems