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.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.
crates=[[3, 3, 3], [3, 3, 3]] → 6
Identical crates can go on top of each other: 3 + 3 = 6.
crates=[[2, 3, 4], [1, 1, 5], [6, 2, 3]]
11
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.