Burst balloons

Dynamic Programming MCM DP Hard
  • This problem, dubbed as the "Burst Balloons" problem, embodies the concept of dynamic programming, an essential technique widely used in software industry to solve optimization problems
  • Its real-world application can be seen in resource allocation tasks where we need to make a sequence of interrelated decisions
  • For example, in network routing, a form of this problem could be used to determine the optimal path (balloons to burst) that would minimize cost (maximize coins) while transferring data from source to destination
  • It stands as a classic example showcasing the importance of decision optimization and state transition in programming

Given n balloons, indexed from 0 to n - 1, each balloon is painted with a number on it represented by an array nums. Burst all the balloons.


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


Return the maximum coins that can be collected by bursting the balloons wisely.

Examples:

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

Output : 167

Explanation :

nums = [3, 1, 5, 8] --> [3, 5, 8] --> [3, 8] --> [8] --> []

coins = 3*1*5  +  3*5*8  + 1*3*8 + 1*8*1 = 167.

Input : nums = [1, 2, 3, 4]

Output : 40

Explanation :

nums = [1, 2, 3, 4] --> [1, 2, 4] --> [1, 4] --> [4] --> []

coins = 2*3*4 + 1*2*4 + 1*1*4 + 1*4*1 = 40.

Input : nums = [1, 5]

Constraints

  • 1 <= n <= 300
  • 1 <= nums[i] <= 100

Hints

  • Define dp[i][j] as the maximum coins obtained by bursting balloons in the range [i, j].
  • "The final burst at k contributes nums[i-1] * nums[k] * nums[j+1] coins. Solve subproblems first, then use them to compute dp[i][j]."

Company Tags

Freshworks HCL Technologies Pinterest Roblox KPMG Optum Goldman Sachs IBM Seagate Technology Target Unity Technologies Byju's Databricks Zynga Broadcom Shopify Cerner Uber Salesforce JPMorgan Chase Square Stripe Robinhood Mastercard Red Hat Google Microsoft Amazon Meta Apple Netflix Adobe