Decode String
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The input is only 30 characters, but the output can hit 10^5, and that gap is the whole problem. Bloomberg reported this Decode String OA in March 2026. Brute-force string expansion that rebuilds on every level will burn time and memory on nested groups. The pattern is a stack over a string, and once you see it the code is about 20 lines. If you blank on the nesting logic during the live assessment, StealthCoder runs invisibly as a safety net and gives you the solution in real time. Know the shape first, though.
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 state when you hit an opening bracket. Keep a current string and a current number. On a digit, build the number (multi-digit counts like 12 or 300 are the classic bug, so do num = num*10 + digit). On '[', push the current string and number, then reset both. On ']', pop the previous string and count, then set current = previous + current * count. On a letter, append it. The common pitfall is treating digits as single characters, or forgetting to reset the number after pushing. Recursion works too, with an index pointer shared across calls. Either way it's linear in output size, which the 10^5 cap allows. StealthCoder is your hedge in the live OA if the push/pop order slips under pressure, but trace Example 2 by hand once and you'll own it.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
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 Bloomberg's OA.
Bloomberg reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Decode String FAQ
How hard is Decode String really?+
It's a medium. The idea is simple once you know a stack handles nesting, but the edge cases trip people: multi-digit counts and resetting state after a push. Most candidates who fail it fail on those two details, not on the concept.
What's the trick for the Bloomberg Decode String OA?+
Push the current string and repeat count onto a stack at every '[', then reset. At every ']', pop and rebuild as previous + current * count. Build numbers digit by digit so 300 parses correctly. That handles all nesting depth.
Should I use a stack or recursion?+
Either passes. The stack version avoids recursion depth worries and is easy to trace by hand. Recursion with a shared index reads cleaner to some people. Pick the one you can write without hesitation, since both are linear in output length.
Is this pattern still asked in 2026?+
Yes. Bloomberg candidates reported it in March 2026. Stack-based parsing of nested structures shows up repeatedly, so the same push/pop-on-bracket idea transfers to related problems like expression evaluation.
How do I prepare in 48 hours?+
Write the stack solution from scratch twice without looking. Then trace 3[a2[c]] and a multi-digit case like 12[ab] on paper. Check that you reset the number after pushing. Finally, test an input with trailing literals like 2[abc]3[cd]ef.