Decode String

Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is repeated exactly k times. You may assume the input is always valid; no extra white spaces, and square brackets are properly matched.

Input Format

s = encoded string

Output Format

decoded string

Constraints

Examples

Example 1:

Input:

s = "3[a]2[bc]"

Output:

aaabcbc

Explanation:

"a" repeated 3 times and "bc" repeated 2 times.

Example 2:

Input:

s = "3[a2[c]]"

Output:

accaccacc

Explanation:

"a2[c]" -> "acc" repeated 3 times.

Loading...
Decode String - Stack DSA Problem