java.lang.Object
g1601_1700.s1691_maximum_height_by_stacking_cuboids.Solution

public class Solution extends Object
1691 - Maximum Height by Stacking Cuboids.<p>Hard</p> <p>Given <code>n</code> <code>cuboids</code> where the dimensions of the <code>i<sup>th</sup></code> cuboid is <code>cuboids[i] = [width<sub>i</sub>, length<sub>i</sub>, height<sub>i</sub>]</code> ( <strong>0-indexed</strong> ). Choose a <strong>subset</strong> of <code>cuboids</code> and place them on each other.</p> <p>You can place cuboid <code>i</code> on cuboid <code>j</code> if <code>width<sub>i</sub> <= width<sub>j</sub></code> and <code>length<sub>i</sub> <= length<sub>j</sub></code> and <code>height<sub>i</sub> <= height<sub>j</sub></code>. You can rearrange any cuboid&rsquo;s dimensions by rotating it to put it on another cuboid.</p> <p>Return <em>the <strong>maximum height</strong> of the stacked</em> <code>cuboids</code>.</p> <p><strong>Example 1:</strong></p> <p><strong><img src="https://assets.leetcode.com/uploads/2019/10/21/image.jpg" alt="" /></strong></p> <p><strong>Input:</strong> cuboids = [[50,45,20],[95,37,53],[45,23,12]]</p> <p><strong>Output:</strong> 190</p> <p><strong>Explanation:</strong></p> <p>Cuboid 1 is placed on the bottom with the 53x37 side facing down with height 95.</p> <p>Cuboid 0 is placed next with the 45x20 side facing down with height 50.</p> <p>Cuboid 2 is placed next with the 23x12 side facing down with height 45.</p> <p>The total height is 95 + 50 + 45 = 190.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> cuboids = [[38,25,45],[76,35,3]]</p> <p><strong>Output:</strong> 76</p> <p><strong>Explanation:</strong></p> <p>You can&rsquo;t place any of the cuboids on the other.</p> <p>We choose cuboid 1 and rotate it so that the 35x3 side is facing down and its height is 76.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]</p> <p><strong>Output:</strong> 102</p> <p><strong>Explanation:</strong></p> <p>After rearranging the cuboids, you can see that all cuboids have the same dimension.</p> <p>You can place the 11x7 side down on all cuboids so their heights are 17.</p> <p>The maximum height of stacked cuboids is 6 * 17 = 102.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == cuboids.length</code></li> <li><code>1 <= n <= 100</code></li> <li><code>1 <= width<sub>i</sub>, length<sub>i</sub>, height<sub>i</sub> <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxHeight

      public int maxHeight(int[][] arr)