File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1117
1117
1196|[ How Many Apples Can You Put into the Basket] ( ./solutions/1196-how-many-apples-can-you-put-into-the-basket.js ) |Easy|
1118
1118
1197|[ Minimum Knight Moves] ( ./solutions/1197-minimum-knight-moves.js ) |Medium|
1119
1119
1198|[ Find Smallest Common Element in All Rows] ( ./solutions/1198-find-smallest-common-element-in-all-rows.js ) |Medium|
1120
+ 1199|[ Minimum Time to Build Blocks] ( ./solutions/1199-minimum-time-to-build-blocks.js ) |Hard|
1120
1121
1200|[ Minimum Absolute Difference] ( ./solutions/1200-minimum-absolute-difference.js ) |Easy|
1121
1122
1201|[ Ugly Number III] ( ./solutions/1201-ugly-number-iii.js ) |Medium|
1122
1123
1202|[ Smallest String With Swaps] ( ./solutions/1202-smallest-string-with-swaps.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1199. Minimum Time to Build Blocks
3
+ * https://leetcode.com/problems/minimum-time-to-build-blocks/
4
+ * Difficulty: Hard
5
+ *
6
+ * You are given a list of blocks, where blocks[i] = t means that the i-th block needs
7
+ * t units of time to be built. A block can only be built by exactly one worker.
8
+ *
9
+ * A worker can either split into two workers (number of workers increases by one) or
10
+ * build a block then go home. Both decisions cost some time.
11
+ *
12
+ * The time cost of spliting one worker into two workers is given as an integer split.
13
+ * Note that if two workers split at the same time, they split in parallel so the cost
14
+ * would be split.
15
+ *
16
+ * Output the minimum time needed to build all blocks.
17
+ *
18
+ * Initially, there is only one worker.
19
+ */
20
+
21
+ /**
22
+ * @param {number[] } blocks
23
+ * @param {number } split
24
+ * @return {number }
25
+ */
26
+ var minBuildTime = function ( blocks , split ) {
27
+ const minHeap = new PriorityQueue ( ( a , b ) => a - b ) ;
28
+
29
+ for ( const block of blocks ) {
30
+ minHeap . enqueue ( block ) ;
31
+ }
32
+
33
+ while ( minHeap . size ( ) > 1 ) {
34
+ const first = minHeap . dequeue ( ) ;
35
+ const second = minHeap . dequeue ( ) ;
36
+
37
+ const mergedTime = split + Math . max ( first , second ) ;
38
+ minHeap . enqueue ( mergedTime ) ;
39
+ }
40
+
41
+ return minHeap . dequeue ( ) ;
42
+ } ;
You can’t perform that action at this time.
0 commit comments