17. Decode the String
β GFG solution to the Decode the String problem: expand encoded patterns k[substring] using stack-based approach for nested bracket handling. π
π§© Problem Description
π Examples
Example 1
Input: s = "3[b2[ca]]"
Output: "bcacabcacabcaca"
Explanation: Inner substring "2[ca]" breaks down into "caca".
Now, new string becomes "3[bcaca]"
Similarly "3[bcaca]" becomes "bcacabcacabcaca" which is the final result.Example 2
Input: s = "3[ab]"
Output: "ababab"
Explanation: The substring "ab" is repeated 3 times giving "ababab".Example 3
π Constraints
β
My Approach
Stack-Based Decoding
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated