Search topics...

Decode String

medium
stringTime: O(maxK × n)Space: O(m + n)Frequency: 4

Given an encoded string in the format k[encoded_string], return the decoded string repeated k times.

Example 1:

Input: s = "3[a]2[bc]"
Output: "aaabcbc"

Example 2:

Input: s = "3[a2[c]]"
Output: "accaccacc"

Example 3:

Input: s = "2[abc]3[cd]ef"
Output: "abcabccdcdcdef"
stack