Expand Given String
Reported by candidates from Cisco's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Cisco's September OA included a string expansion problem that tests whether you can parse a compact notation and rebuild it correctly. The trick isn't complex logic but getting the parsing right. You need to handle nested structures, digit-to-multiplier conversions, and possibly recursive expansion. If you blank on the exact algorithm during the live OA, StealthCoder reads the problem and feeds you the pattern in real time so you don't lose points on a careless mistake.
Pattern and pitfall
String expansion problems typically use a stack or recursion to track nesting levels and multipliers. The common pitfall is forgetting to handle edge cases like consecutive multipliers, digits that are part of the string versus digits that are multipliers, and correctly popping/rebuilding when you hit a closing bracket. The pattern is almost always: iterate through each character, push to a stack when you see an opening bracket, multiply and concatenate when you see a closing bracket, and track the current multiplier as you go. Most candidates either miss a case or write inefficient string concatenation. StealthCoder lets you verify your approach against the actual test input before you submit, reducing the sting of off-by-one errors.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Expand Given 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 Cisco's OA.
Cisco 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.
Expand Given String FAQ
Is this just regex or do I need to build a parser?+
Regex won't handle nested brackets cleanly. You need a stack-based or recursive approach. Iterate through the string, maintain a stack of characters and multipliers, and reconstruct when you hit closing brackets. Most solutions run in O(n) time after expansion.
How do I handle digits that are multipliers versus digits in the string?+
Multipliers appear before brackets. When you see a digit, check if the next character is an opening bracket. If yes, it's a multiplier. If no, it's part of the string itself. Track the current multiplier as you build the stack.
Can there be nested brackets like 2[a2[b]]?+
Very likely. Use a stack to track nested levels. When you hit a closing bracket, pop the top level, apply the multiplier to it, and push the result back. Repeat until the stack is empty. This handles arbitrary nesting depth.
What's the most common mistake candidates make?+
Forgetting to reset the current multiplier after processing a bracket, or concatenating strings inefficiently instead of using a list and joining at the end. Also, not handling single-digit multipliers correctly when they appear back-to-back.
How much time do I need to code this?+
15-25 minutes if you know the stack pattern. If you're unsure, write it out on paper first: trace through a small example like '2[a3[b]]' to see how the stack grows and shrinks. That clarity is worth the time.