Burst Balloons problem is one of the classical problems of Dynamic Programming. Let us understand the problem in detail in order to get a Solution to the Burst Balloons Problem.
You are given n balloons with indices ranging from 0 to N - 1. Each balloon has a number painted on it, which is represented by an array 'nums'. You are instructed to burst all of the balloons.
You will receive (nums[i - 1] * nums[i] * nums[i + 1]) coins if you burst the ith balloon where (0<i<nums.length-1)
If i - 1 or i + 1 is beyond the array's limits, consider it as if it were a balloon with a 1 painted on it. Burst the Balloons in such a way that you get the maximum number of coins.
Let us see some Example Testcases.
TestCase 1
Input : [4,1,6,9,3,7]
Output : 794
TestCase 2
Input : [5,5,5,5,5]
Output : 405
TestCase 3
Input : [4]
Output : 4
Here is the Approach that we use to solve this problem. we can solve this either by memoization or by using a recursive approach.
In order to solve the greater problem, we have to solve this problem at smaller problems. we will get answers to another subarray on basis of answers of other smaller subarrays.
Solution using Memoization
Solution to Burst Balloons Problem in C++
Solution to Burst Balloons Problem in Java
Keep learning with us!
solve this problem on Leetcode - Burst Balloons Problem