234. Decode String

MediumStringString

Given an encoded string with the rule k[encoded_string] meaning the inner string repeated k times (k is a positive integer), return the decoded string. Encodings may be nested.

Input: A quoted encoded string.

Output: Quoted string — the decoded result.

Examples

Example 1
Input: "3[a]"
Output: "aaa"
Explanation: 'a' repeated 3 times.
Example 2
Input: "3[a2[c]]"
Output: "accaccacc"
Explanation: Nested decoding.
Example 3
Input: "2[abc]3[cd]ef"
Output: "abcabccdcdcdef"
Explanation: Sequential blocks.

Constraints

Asked by

BloombergGoogleOracleMetaAmazonApple
Solve this problem in the editor →