Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Interval DP: choose the last balloon to burst in each interval.

Approach

Pad with 1s: a = [1] + nums + [1]. Let dp[l][r] = max coins from bursting balloons strictly between indices (l, r). Pick last burst k in (l,r): dp[l][r] = max(a[l]*a[k]*a[r] + dp[l][k] + dp[k][r]). Compute by increasing interval length.

Code
Loading...
Complexity
Time: O(n^3)
Space: O(n^2)
Solution
Updated: 2026-02-23

Idea

Interval DP: choose the last balloon to burst in each interval.

Approach

Pad with 1s: a = [1] + nums + [1]. Let dp[l][r] = max coins from bursting balloons strictly between indices (l, r). Pick last burst k in (l,r): dp[l][r] = max(a[l]*a[k]*a[r] + dp[l][k] + dp[k][r]). Compute by increasing interval length.

Code
Loading...
Complexity
Time: O(n^3)
Space: O(n^2)