Back to DSA

Decode String

medium
Acceptance: 49%
StackStringRecursion

Decode a string that has been encoded with the pattern k[substring], where k is a positive integer and substring is the text to be repeated k times. Brackets may be nested. Assume the input is always syntactically correct with no extraneous spaces.

Examples

Example 1:
Input:s = "2[xy]3[z]"
Output:"xyxyzzzz"
Example 2:
Input:s = "2[a3[b]]"
Output:"abbbabbb"

Hints

00:00
1234567