Decode String
Reported by candidates from Abridge's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Brute force sounds fine until you read the constraints on this Abridge OA, reported in September 2026. The input string is at most 30 characters, but the decoded output can hit 10^5 and repeat counts go up to 300. So you can't expand blindly and rescan. This is Decode String, a stack problem wearing a string costume. Nested brackets, multi-digit counts, trailing literals. If your brain freezes on the nesting, StealthCoder is the safety net running invisibly during the live OA. Know the stack approach cold and you won't need it.
The problem
Given a valid encoded string s, return its decoded form. An encoded group has the form k[encodedString], meaning that encodedString is repeated exactly k times. Groups may be nested, and a repeat count may contain multiple digits. The unencoded text contains lowercase English letters. Digits appear only as repeat counts immediately before bracketed groups. Function decodeString(s: String) → String Examples Example 1 s = "3[a]2[bc]" return = "aaabcbc" Repeat a three times and bc twice, then concatenate the two decoded parts. Example 2 s = "3[a2[c]]" return = "accaccacc" The inner group becomes cc, so the outer group repeats acc three times. Example 3 s = "2[abc]3[cd]ef" return = "abcabccdcdcdef" Decode the two adjacent repeated groups, then retain the trailing literal ef. Constraints 1 <= s.length <= 30. s contains lowercase English letters, digits, and square brackets. s is a valid encoding with well-formed brackets. Every repeat count is between 1 and 300. The decoded output length does not exceed 10^5.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a stack that saves context at every open bracket. Walk the string once. Build the current number digit by digit (so 12[a] works). Build the current string from letters. On '[', push the current string and the current count, then reset both. On ']', pop the previous string and count, and set current to previous + current * count. At the end, current is your answer. The common pitfall is parsing a single digit and breaking on counts like 300 or 10. Another is recursing with wrong index handling when brackets nest. Build with a list and join, not repeated concatenation in a loop. The output cap of 10^5 means output-sized work is fine, so don't over-optimize. If you blank on the stack frame details during the live OA, StealthCoder can supply the solution while you keep typing naturally.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Decode String cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as decode string. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Abridge's OA.
Abridge reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Decode String FAQ
What's the trick to Decode String?+
Use a stack that stores the string built so far and the repeat count whenever you hit '['. On ']', pop both and append current repeated count times to the previous string. One pass, no re-scanning. The only real work is tracking state at each bracket.
How hard is this Abridge OA question really?+
Medium. The logic is short once you see the stack, but nested groups and multi-digit counts trip people up. If you've written a bracket-matching solution before, you can finish this quickly. The bugs live in number parsing, not the algorithm.
Should I use recursion or a stack?+
Either works. The stack is easier to debug because state is explicit. Recursion is shorter but you must track a shared index across calls. With nesting this shallow (input length 30), neither will hit depth issues. Pick the one you can write without bugs.
What mistakes fail hidden tests here?+
Reading only one digit for the count, so 100[a] breaks. Forgetting trailing literals after the last bracket, like the ef in example 3. Resetting the count after pushing. Also test a plain string with no brackets, which is valid input.
How do I prepare in 48 hours?+
Write this solution from scratch twice without looking. Then trace 3[a2[c]] by hand, tracking the stack at each step. Do one related bracket problem for warmup. That's enough. The pattern is small, so repetition on the state transitions matters more than breadth.