PPractick

DSA interview question

Burst Balloons

Hard · Algorithms · Topics: dynamic programming, mcm, partition

The problem

You're designing the finale sequence for a fireworks show controlled by a game studio's physics engine. There are n balloons lined up in a row, each painted with a number representing its "coin value." When you burst a balloon, you collect left * current * right coins, where left and right are the values of the adjacent balloons at the time of bursting (not their original neighbors — once a balloon is burst, its former neighbors become adjacent to each other). If there's no balloon on one side (off the boundary), treat that side's value as 1. Your job: figure out the order to burst all balloons in to maximize total coins collected.

Example: nums = [3,1,5,8] — bursting in the right order gives 167 coins, achieved by bursting 1, then 5, then 3, then 8.

Function signature

int maxCoins(vector<int>& nums);

Test cases

Input numsOutputExplanation
[3,1,5,8]167Burst order: 1→5→3→8 gives 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 15+120+24+8=167
[1,5]10Burst 1 first: 1*1*5=5, then burst 5: 1*5*1=5 → total 10
[]0No balloons, no coins
[7]7Single balloon: 1*7*1 = 7
[3,1,5]35Optimal order yields 35

(Constraints typically: n == nums.length, 0 <= n <= 300, 0 <= nums[i] <= 100)

How interviewers phrase it

Clarifying questions to ask

  1. When a balloon is burst, do its neighbors permanently become adjacent for all future bursts, or does adjacency reset? (Confirm: yes, it's a real removal — left and right close the gap.)
  2. What value do I use for "out of bounds" neighbors — is it always 1, or could it vary? (Standard: always 1.)
  3. Can nums contain 0s? Does that change strategy? (Doesn't change the algorithm, but worth confirming since a 0-value balloon contributes nothing when burst directly but could still matter as a multiplier if burst at the wrong time — actually since it's a multiplier either way, 0s are handled naturally by the DP.)
  4. What's the expected array size — n up to 300 suggests O(n³) DP is intended (300³ = 27M, feasible) rather than something more exotic.

Follow-ups to expect

  1. "Why doesn't a 'burst first' greedy/DP approach work?"
  2. "Can you reconstruct the actual burst order, not just the max coins?"
  3. "What's the time and space complexity, and can you optimize space?"
  4. "How is this related to Matrix Chain Multiplication?"
  5. "What if you wanted to minimize the coins instead of maximize?"
  6. "Can you do this without padding the array with 1s at the boundaries?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in