15% off all plans & roadmaps Use code
See plansLeetCode 546 · Solution & editorial
You are given several boxes with different colors represented by different positive numbers.
Remove Boxes is a Dynamic Programming (DP) Patterns problem, in the Interval DP subpattern. The pattern covers fibonacci, Kadane, knapsack, LCS, LIS, edit distance, grid paths, and word break
Solve problems on intervals like burst balloons and matrix chain multiplication using interval DP.
The reference solution runs in O(n^3) time and O(n^3) space.
Remove Boxes has been reported in interviews at Apple, Amazon.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Remove Boxes is a Dynamic Programming (DP) Patterns problem, in the Interval DP subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.