166. Decode a Nested String
Challenge1000 ms256 MBSolved by 0%
A string is encoded as k[content], meaning the content repeats k times.
Encodings may be nested, so 2[a3[b]] decodes to abbbabbb.
Read one encoded line and print the decoded string.
The input is always valid, k is at least 1, and the decoded result is at most 100000
characters.
Constraints - The line has between 1 and 10000 characters. - Lowercase letters, digits, `[` and `]` only. - The decoded result fits in 100000 characters.
Input
A single line containing lowercase letters, digits, [ and ]. The encoding is always valid.
Output
Print the decoded string.
Input3[a]
Outputaaa
Noteis a single repetition with no nesting
Input2[a3[b]]
Outputabbbabbb
Notenests one encoding inside another
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution