InterviewDB Question

Array Reduction 4: Reduce an Array by Repeatedly Removing the Minimum Pair Sum

Question Details

Problem Given an integer array, repeatedly perform the following operation until one element remains: Find the two smallest elements, remove them, and insert their sum back into the array. Return the total cost (sum of all inserted sums across all operations). This is equivalent to building an optimal merge tree (Huffman-style). Example: Approach Use a min-heap. At each step, pop two smallest elements, compute their sum, accumulate cost, and push the sum back. Time: O(n log n). Follow-ups Why do…

Full Details

🔒

Unlock all Snowflake questions

Full insider details, leaked discussions, and candidate experiences.

or every company, $100/year →

About This Question

This is a reported interview question from a snowflake interview during the oa round.

It covers the following topics: Heap, Oa, Greedy, Coding, Arrays .