Skip to content

Practice Maximum Height by Stacking Cuboids

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1691
LeetCode Problem

Maximum Height by Stacking Cuboids

Problem Statement

Given n cuboids where the dimensions of the ith cuboid is 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 and 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.

Source: Maximum Height by Stacking Cuboids on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
cuboids = [[50,45,20],[95,37,53],[45,23,12]]
Output
190

# Example 2

Input
cuboids = [[38,25,45],[76,35,3]]
Output
76

# Example 3

Input
cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]
Output
102

Constraints

n == cuboids.length
1 <= n <= 100
1 <= widthi, lengthi, heighti <= 100

Related LeetCode Problems

Practice more problems similar to Maximum Height by Stacking Cuboids .

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.