Medium
Quiz
#394 Decode String
APPROACH
An encoded string uses the format k[t] to mean substring t is repeated exactly k times (k is a positive integer). These encodings can nest to any depth.
The input is always well-formed: brackets are balanced, there are no spaces, and digits only serve as repetition counts (no input like 3a or 2[4]). The fully decoded string never exceeds 105 characters.
Return the fully decoded string.
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"
1 of 4
1:00
What is the optimal approach for this problem?