nums
array to handle edge cases.dp
where dp[left][right]
represents the maximum coins obtainable by bursting all balloons between left
and right
.n
.left
.right
based on the current length and starting point.i
between left
and right
, calculate the coins obtained by assuming the i
th balloon is the last to burst.i
plus the coins from bursting the i
th balloon itself, considering the neighbors.dp[left][right]
with the maximum coins obtained for all positions i
.dp[1][n-2]
as the final answer, excluding the fake balloons added in step 1.