File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 1- # 1,478 LeetCode solutions in JavaScript
1+ # 1,479 LeetCode solutions in JavaScript
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
130313031688|[ Count of Matches in Tournament] ( ./solutions/1688-count-of-matches-in-tournament.js ) |Easy|
130413041689|[ Partitioning Into Minimum Number Of Deci-Binary Numbers] ( ./solutions/1689-partitioning-into-minimum-number-of-deci-binary-numbers.js ) |Medium|
130513051690|[ Stone Game VII] ( ./solutions/1690-stone-game-vii.js ) |Medium|
1306+ 1691|[ Maximum Height by Stacking Cuboids] ( ./solutions/1691-maximum-height-by-stacking-cuboids.js ) |Hard|
130613071716|[ Calculate Money in Leetcode Bank] ( ./solutions/1716-calculate-money-in-leetcode-bank.js ) |Easy|
130713081718|[ Construct the Lexicographically Largest Valid Sequence] ( ./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js ) |Medium|
130813091726|[ Tuple with Same Product] ( ./solutions/1726-tuple-with-same-product.js ) |Medium|
Original file line number Diff line number Diff line change 1+ /**
2+ * 1691. Maximum Height by Stacking Cuboids
3+ * https://leetcode.com/problems/maximum-height-by-stacking-cuboids/
4+ * Difficulty: Hard
5+ *
6+ * Given n cuboids where the dimensions of the ith cuboid is cuboids[i] = [widthi, lengthi, heighti]
7+ * (0-indexed). Choose a subset of cuboids and place them on each other.
8+ *
9+ * You can place cuboid i on cuboid j if widthi <= widthj and lengthi <= lengthj and
10+ * heighti <= heightj. You can rearrange any cuboid's dimensions by rotating it to put it on
11+ * another cuboid.
12+ *
13+ * Return the maximum height of the stacked cuboids.
14+ */
15+
16+ /**
17+ * @param {number[][] } cuboids
18+ * @return {number }
19+ */
20+ var maxHeight = function ( cuboids ) {
21+ const sortedCuboids = cuboids . map ( dim => dim . sort ( ( a , b ) => a - b ) )
22+ . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] || a [ 1 ] - b [ 1 ] || a [ 2 ] - b [ 2 ] ) ;
23+ const n = sortedCuboids . length ;
24+ const maxHeights = new Array ( n ) . fill ( 0 ) ;
25+ let result = 0 ;
26+
27+ for ( let i = 0 ; i < n ; i ++ ) {
28+ maxHeights [ i ] = sortedCuboids [ i ] [ 2 ] ;
29+ for ( let j = 0 ; j < i ; j ++ ) {
30+ if ( sortedCuboids [ j ] [ 0 ] <= sortedCuboids [ i ] [ 0 ]
31+ && sortedCuboids [ j ] [ 1 ] <= sortedCuboids [ i ] [ 1 ]
32+ && sortedCuboids [ j ] [ 2 ] <= sortedCuboids [ i ] [ 2 ] ) {
33+ maxHeights [ i ] = Math . max ( maxHeights [ i ] , maxHeights [ j ] + sortedCuboids [ i ] [ 2 ] ) ;
34+ }
35+ }
36+ result = Math . max ( result , maxHeights [ i ] ) ;
37+ }
38+
39+ return result ;
40+ } ;
You can’t perform that action at this time.
0 commit comments