Maximum Height by Stacking Cuboids
Given n cuboids where the dimensions of the i^th cuboid are cuboids[i] = [widthi, lengthi, heighti] (0-indexed). Choose a subset of cuboids and place them on each other.
You can place cuboid i on cuboid j if widthi <= widthj, lengthi <= lengthj, and heighti <= heightj. You can rearrange any cuboid's dimensions by rotating it to put it on another cuboid.
Return the maximum height of the stacked cuboids.
Example 1
Input
cuboids = [[50,45,20],[95,37,53],[45,23,12]]Output
190Cuboid 1 is placed on the bottom with height 95, cuboid 0 is placed next with height 50, and cuboid 2 is placed next with height 45, for a total height of 190.
Example 2
Input
cuboids = [[38,25,45],[76,35,3]]Output
76You can't place either cuboid on the other, so choosing cuboid 1 and rotating it gives a maximum height of 76.
Constraints
- n == cuboids.length
- 1 <= n <= 100
- 1 <= widthi, lengthi, heighti <= 100