
Problem
Solution
Submissions
Burst Balloons
Certification: Advanced Level
Accuracy: 0%
Submissions: 0
Points: 15
Write a C program to find the maximum coins you can collect by bursting balloons. You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons. If you burst the i-th balloon, you will get nums[i - 1] * nums[i] * nums[i + 1] coins. If i - 1 or i + 1 goes out of bounds of the array, then treat it as if there is a balloon with a 1 painted on it. Return the maximum coins you can collect by bursting the balloons wisely.
Example 1
- Input: nums = [3,1,5,8]
- Output: 167
- Explanation:
- Burst balloon at index 1 (value 1): coins = 3*1*5 = 15, remaining = [3,5,8].
- Burst balloon at index 1 (value 5): coins = 3*5*8 = 120, remaining = [3,8].
- Burst balloon at index 0 (value 3): coins = 1*3*8 = 24, remaining = [8].
- Burst balloon at index 0 (value 8): coins = 1*8*1 = 8, remaining = [].
- Total coins = 15 + 120 + 24 + 8 = 167.
- Burst balloon at index 1 (value 1): coins = 3*1*5 = 15, remaining = [3,5,8].
Example 2
- Input: nums = [1,5]
- Output: 10
- Explanation:
- Burst balloon at index 0 (value 1): coins = 1*1*5 = 5, remaining = [5].
- Burst balloon at index 0 (value 5): coins = 1*5*1 = 5, remaining = [].
- Total coins = 5 + 5 = 10.
- Burst balloon at index 0 (value 1): coins = 1*1*5 = 5, remaining = [5].
Constraints
- n == nums.length
- 1 ≤ n ≤ 300
- 0 ≤ nums[i] ≤ 100
- Time Complexity: O(n^3)
- Space Complexity: O(n^2)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use dynamic programming with interval-based approach
- Add boundary balloons with value 1 at both ends
- For each interval [left, right], try bursting each balloon as the last one
- When bursting balloon k last in interval [left, right], multiply values[left] * values[k] * values[right]
- Use memoization to store results for overlapping subproblems
- Build solution bottom-up from smaller intervals to larger ones