Minimum Cost to Merge Package Bundles Into One Pallet

Last updated: November 29, 2026

Quick Overview

A dock has bundles of packages with given sizes. Merging two bundles costs the sum of their sizes and produces one bundle of that combined size. Return the minimum total cost to merge all bundles into a single pallet.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


A dock has bundles of packages with given sizes. Merging two bundles costs the sum of their sizes and produces one bundle of that combined size. Return the minimum total cost to merge all bundles into a single pallet.

A greedy heap problem in the style of Amazon assessments about consolidation at a sortation center. Graders expect a min-heap that always merges the two smallest bundles, plus a short argument for why that is optimal (it is the Huffman coding argument).

What the Interviewer Expects
  • Use a min-heap
  • Always merge the two smallest bundles
  • Explain the Huffman-style optimality argument
  • Use 64-bit safe arithmetic or note Python ints are unbounded
  • Handle zero or one bundle
Key Topics to Cover
Heaps
Greedy
Huffman Coding
Priority Queue
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if only adjacent bundles on the conveyor can be merged?
  • What if you can merge three bundles at a time?
  • How would you return the merge order for operators?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Sizes is a list of positive ints, possibly empty or length 1 (cost 0). Return the minimum total cost as an int....

High-Level Design

Each bundle's size is added to the total once for every merge it participates in, which equals its depth in the binary merge tree. Minimizing sum(size * depth) is exactly building a Huffman tree, wher...


Submit Your Answer
Markdown supported