Dsa
Stack
Medium
Scoped Multiplier Expansion
Expand a nested expression where each scope starts with a multiplier. The format is '(multiplier item1 item2 ...)', where an item can be an integer or another nested scope. When an integer is inside a scope, it is multiplied by the scope's multiplier and all parent multipliers. Output the flattened list of expanded integers. Input is a single string of nested parentheses and integers.
Example:
(2 5 (3 1 2) 4)
1. 5 is in scope with multiplier 2 -> 10
2. 1 is in nested scope (3) inside (2) -> 1 * 3 * 2 = 6
3. 2 is in nested scope (3) inside (2) -> 2 * 3 * 2 = 12
4. 4 is in scope with multiplier 2 -> 8
Output: 10 6 12 8
Key concepts
stackparsing
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now