LeetCode 394 Decode String - Solution

The core idea

Use two stacks: one for counts, one for accumulated strings.

When you see a digit, build the number (could be multi-digit like "123").

When you see [, push the current count and current string onto their stacks. Reset both for the nested context.

When you see ], pop the count and previous string. Repeat the current string that many times and append it to the previous string.

When you see a letter, add it to the current string.