← Accenture bank

Accenture · Question 73 · Dynamic Programming

Burst Balloons

Dynamic ProgrammingC++code⏱ O(n³)💾 O(n²)
Service-based

Problem

Max coins by bursting balloons wisely.

Approach

Use interval DP to find max coins between balloons.

Time O(n³)Space O(n²)

How it works

  1. 1Pad with virtual 1-balloons.
  2. 2dp[left][right] tries each balloon as last burst inside.

Sample input / output

Input:
nums = [3, 1, 5, 8]
Output:
167

Constraints

1 <= n <= 300.

Solution — read it, then walk it

Time O(n³)Space O(n²)Loops 4Returns 2source · C++
Scroll sideways for wide charts — the view follows the active step.
↻ repeat↻ repeat↻ repeatSTARTinclude <iostream>include <vector>include <algorithm>using namespace stdDEFINEmaxCoins(std::vector<int>&nums)DEFINE n = nums.size()std::vector<int> balloons(n+ 2, 1)for (int i = 0; i < n;++i) balloons[i + 1] =nums[i]std::vector<std::vector<int>>dp(n + 2,std::vector<int>(n + 2, 0))for (int length = 1;length <= n; ++length)for (int left = 1;left <= n - length +1; ++left)DEFINE right = left +length - 1for (int k = left; k<= right; ++k)dp[left][right] =std::max(dp[left][right],RETURN dp[1][n]DEFINE main()std::vector<int> nums = {3,1, 5, 8}cout << maxCoins(nums) <<endlRETURN 0END
  • start / end
  • statement
  • condition
  • loop
  • returns
  • definition
1/20

StartSTART

Interactive control-flow diagram and step-by-step code walkthrough.

Recommended resourcesAffiliate links · may earn us a commission

Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits