Burst Balloons

Burst Balloons is a Hard Data Structures and Algorithms interview problem you can solve, run and submit on Thita.ai. It belongs to the Dynamic Programming (DP) Patterns pattern, in the Interval DP subpattern.

Problem statement

You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.

If you burst the ith balloon, you will get nums[i - 1] nums[i] nums[i + 1] coins. If i - 1 or i + 1 goes out of bounds of the array, then treat it as if there is a balloon with a 1 painted on it.

Return the maximum coins you can collect by bursting the balloons wisely.

Example 1:

Input: nums = [3,1,5,8] Output: 167 Explanation: nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> [] coins = 315 + 358 + 138 + 181 = 167

Example 2:

Input: nums = [1,5] Output: 10

Constraints:

- n == nums.length

- 1 <= n <= 300

- 0 <= nums[i] <= 100

Topics and companies

Topics: Array, Dynamic Programming.

Reported in interviews at Adobe, Bloomberg, Amazon, Google, Codenation.

How to practise Burst Balloons on Thita.ai

Starter code is provided in C, C#, C++, Go, Java, JavaScript and Python. Your solution runs against 5 test cases for this problem, with the AI coach available for a hint when you are stuck rather than a finished answer. The reference solution runs in O(n^3) time and O(n^2) space.

Open Burst Balloons in the code editor, or read the Burst Balloons editorial for a worked solution with its approach and complexity analysis.

Where Burst Balloons sits in the DSA pattern sheet

Problems related to Burst Balloons

Other problems that use the same Interval DP and Dynamic Programming (DP) Patterns techniques:

Opening the problem

Progress is saved as you study.