208. Decode String (Nested Brackets — Easy Variant)

EasyStringString

Given an encoded string s, return its decoded version.

The encoding rule is: k[encoded_string], where encoded_string is repeated k times.

Brackets may be nested. k is always a positive integer.

Examples: '3[a]2[bc]' → 'aaabcbc'; '3[a2[c]]' → 'accaccacc'.

Input: A single encoded string s.

Output: The decoded string.

Examples

Example 1
Input: 3[a]2[bc]
Output: aaabcbc
Explanation: 3×'a'=aaa, 2×'bc'=bcbc → 'aaabcbc'.
Example 2
Input: 3[a2[c]]
Output: accaccacc
Explanation: 2×'c'=cc; a+cc=acc; 3×acc=accaccacc.
Example 3
Input: 2[abc]3[cd]ef
Output: abcabccdcdcdef
Explanation: 2×abc + 3×cd + ef.

Constraints

Asked by

BloombergGoogleOracleMetaAmazonApple
Solve this problem in the editor →