Ctrl K

The Tallest Tower of Crates

Hard
There are n box-shaped crates; crates[i] = [a, b, c] gives the dimensions of crate i. A crate can be turned any way you like, so any of its three dimensions can serve as width, length or height. Pick some crates and stack them into a tower. A crate may be placed on another only if, after turning, each of its three dimensions (width, length and height) is no larger than the matching dimension of the crate below. Return the greatest height the tower can reach.
Example 1
crates=[[2, 3, 4], [1, 1, 5], [6, 2, 3]] → 11

At the bottom is the crate [6, 2, 3] standing on its 2 × 3 face, 6 tall. On top goes [1, 1, 5] on its 1 × 1 face, 5 tall. The total is 11.

Example 2
crates=[[3, 3, 3], [3, 3, 3]] → 6

Identical crates can go on top of each other: 3 + 3 = 6.

Constraints
  • 1 ≤ len(crates) ≤ 100
  • len(crates[i]) = 3
  • 1 ≤ crates[i][j] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBoxes Inside Boxes HardStrict Climb From Spare Parts HardBest-Paying Set of Gigs HardLongest Downhill Route HardBiggest Number Divisible by Three Hard
loading Python…
Input
crates=[[2, 3, 4], [1, 1, 5], [6, 2, 3]]
Expected
11

Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.