Coders Crushby Napplied AI
Back to DSA Problems
HardDynamic Programming

Burst Balloons

Maximum coins from bursting balloons

Solution Approach

DP on intervals. Think backwards: last balloon to burst in range. Combine subproblems.

Implementation
def maxCoins(nums):
    n = len(nums)
    balloons = [1] + nums + [1]
    dp = [[0] * (n + 2) for _ in range(n + 2)]
    
    for length in range(3, n + 3):
        for left in range(n + 2 - length):
            right = left + length - 1
            for mid in range(left + 1, right):
                dp[left][right] = max(dp[left][right],
                    balloons[left] * balloons[mid] * balloons[right] +
                    dp[left][mid] + dp[mid][right])
    
    return dp[0][n + 1]
Complexity Analysis

Time Complexity

O(n³)

Space Complexity

O(n²)
Complexity
Time:O(n³)
Space:O(n²)
Asked at
GoogleAmazon
Coders Crushby Napplied AI

The ultimate interview preparation platform. Master System Design, DSA, and tackle community challenges to crush your FAANG interviews.

Looking for jobs? Visit Napplied AI Jobs Search Agent

System Design

  • All Problems
  • Easy
  • Hard

DSA

  • All Problems
  • Dynamic Programming
  • Graphs

More

  • Problems Arena
  • Growth Paths
  • My Crush

Coders Crush by Napplied AI - Tech Interview & Coding Should Be Effortless