File tree 2 files changed +42
-1
lines changed
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
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1303
1303
1688|[ Count of Matches in Tournament] ( ./solutions/1688-count-of-matches-in-tournament.js ) |Easy|
1304
1304
1689|[ Partitioning Into Minimum Number Of Deci-Binary Numbers] ( ./solutions/1689-partitioning-into-minimum-number-of-deci-binary-numbers.js ) |Medium|
1305
1305
1690|[ 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|
1306
1307
1716|[ Calculate Money in Leetcode Bank] ( ./solutions/1716-calculate-money-in-leetcode-bank.js ) |Easy|
1307
1308
1718|[ Construct the Lexicographically Largest Valid Sequence] ( ./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js ) |Medium|
1308
1309
1726|[ 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