612. Decode String (Nested Brackets)

MediumStackStackString

Given an encoded string where k[encoded] means the bracketed substring repeats k times (nesting allowed), return the fully decoded string. The input is JSON {s}.

Input: JSON {s}.

Output: String — the decoded string.

Examples

Example 1
Input: {"s":"3[a]2[bc]"}
Output: aaabcbc
Explanation: a x3 then bc x2.
Example 2
Input: {"s":"3[a2[c]]"}
Output: accaccacc
Explanation: Nested repetition.
Example 3
Input: {"s":"abc"}
Output: abc
Explanation: No encoding.

Constraints

Asked by

BloombergGoogleOracleMetaAmazonApple
Solve this problem in the editor →