←ENG-DSA-075Nested Payload Decoder (Stack)
00:00
🐍 Python Idle
Mode:Web

Nested Payload Decoder (Stack)

CompaniesStripe, Twilio
Est. Time~35 min
LevelMid
StackStrings
🚨 P0 Incident
StripeTwilio

To minimize payload sizes over constrained networks, mobile APIs sometimes compress redundant JSON data structures. A payload encoded as "3[msg]" needs to be expanded into "msgmsgmsg". Nested compression like "2[b3[a]]" requires evaluating structures from the inside out.

πŸ“₯ Assigned to:You β€” Mid Engineer
Your Task

Given an encoded string, return its decoded string. The encoding rule is: `k[encoded_string]`, where the encoded_string inside the square brackets is being repeated exactly `k` times. Note that `k` is guaranteed to be a positive integer.

⏱ Time: O(Max Output Length)πŸ’Ύ Space: O(Max Output Length)
Example 1
Input:Β Β s="3[a]2[bc]"
Output:Β "aaabcbc"
Example 2
Input:Β Β s="3[a2[c]]"
Output:Β "accaccacc"
πŸ”’ +3 hidden test cases β€” revealed on Submit
Hints
Loading editor…
Test Output
β–Ά Run Code to test against examples Β· Submit to judge all 5 test cases
EngPrep β€” Real Engineering. Real Interviews.