The Minimum Time to Build Blocks problem gives you a list of blocks, each requiring a certain build time. Workers can split into two groups at any time (at a cost called "split time"), and each worker can only build one block. Find the minimum total time to build all blocks. This Minimum Time to Build Blocks coding problem is a greedy problem with a counterintuitive optimal strategy powered by a min-heap.
Google asks this hard problem because its optimal strategy is non-obvious: instead of assigning workers to blocks greedily from largest to smallest, the optimal approach works backwards — merging blocks (like Huffman coding). The array, math, heap, and greedy interview pattern is demonstrated with a clever observation that mirrors Huffman tree construction.
Greedy with min-heap (Huffman-style merging). Think backwards: instead of splitting workers, merge blocks. Put all block times in a min-heap. Repeatedly extract the two smallest times, "merge" them by keeping the larger (one worker handles the larger block; split cost is paid to generate the second worker). The merged cost is max(t1, t2) + split. Push this merged cost back. Repeat until one block remains. The final value in the heap is the answer.
Blocks: [1, 2, 3], split = 1.
Alternative: directly build block 3 (time=3), split to handle 1 and 2 simultaneously (time = max(1,2) + split = 3). Total = 3. Actually let's verify: with 1 worker, split costs 1 → 2 workers. One handles block 3 (time=3). The other splits again at cost 1 → 2 workers handle blocks 1 and 2 simultaneously (time=max(1,2)=2). Total time from split: 1 + max(3, 1+2) = 1+3 = 4. Confirmed.
Anytime you see "minimum time with parallel workers that can split," think Huffman tree construction. The reverse-simulation (merge instead of split) is the key insight. Huffman coding solves a structurally identical problem: combine smallest elements, paying a merge cost each time. Practice Huffman coding first to internalize why combining the smallest values first is optimal, then apply the same reasoning here. Recognizing structural analogies between problems is a top-tier interview skill.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Replacements to Sort the Array | Hard | Solve | |
| Maximum Score From Removing Stones | Medium | Solve | |
| Maximum Product After K Increments | Medium | Solve | |
| Maximal Score After Applying K Operations | Medium | Solve | |
| Maximum Average Pass Ratio | Medium | Solve |