Home › Company-wise questions › Accenture › Burst Balloons ← Accenture bank
Accenture · Question 73 · Dynamic Programming
Burst Balloons Dynamic Programming C++ code ⏱ O(n³) 💾 O(n²)
Service-based Published and maintained by DSA-topics · Last updated 30 November 2026 · Report an error
About this bank These are classic technical-interview concepts compiled from publicly circulated company-wise question sets, rewritten with original explanations and compiler-ready solutions for educational practice; inclusion does not imply endorsement by the company. Spotted an error? Tell us .
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 Pad with virtual 1-balloons. 2 dp[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 Flowchart Pseudocode
Time O(n³)Space O(n²)Loops 4Returns 2source · C++
Scroll sideways for wide charts — the view follows the active step. ⤢ Expand
↻ repeat ↻ repeat ↻ repeat START using namespace std DEFINE maxCoins(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 - 1 for (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) << endl RETURN 0 END start / end statement condition loop returns definition← Q72 · Word Break Q74 · Regular Expression Matching → Solution code Core logic highlighted in green
Language Python Java C++source C Core logic Full code Copy
Recommended resources Affiliate links · may earn us a commission
Classic DSA interview books The reference books interviewers themselves learned from — great next to the visualizers. See the books → Structured coding courses Video courses that pair well with visual practice — pick one language and go deep. Browse courses → Cloud hosting for side projects Ship the portfolio project that gets you hired — free credits for new accounts. Claim credits →