LeetCode 394: Decode String by Saving and Restoring Nested Context

Problem Requirement Given an encoded string s, return its decoded string. The encoding rule is: k[encoded_string] The encoded_string inside the brackets is repeated exactly k times, where k is a positive integer. Encodings may be nested or adjacent to ordinary lowercase letters. The problem guarantees that: The input is always valid, with matching brackets and no extra spaces. Original text contains no digits; digits only represent repeat counts. Inputs such as 3a or 2[4] do not occur. The decoded string length does not exceed 10^5. Examples Input Output "3[a]2[bc]" "aaabcbc" "3[a2[c]]" "accaccacc" "2[abc]3[cd]ef" "abcabccdcdcdef" Constraints 1 <= s.length <= 30 s contains only lowercase English letters, digits, and [] Every repeat count is in [1, 300] LeetCode provides this method signature: ...

August 21, 2026 · 10 min · map[name:Jeanphilo]