Dsa
Heap
Easy
The Synergy Merger
In a corporate simulation, you have N startups with different 'Market Valuations'. You can merge any two startups into a single entity. The cost of merging two startups is equal to the sum of their current valuations. The new valuation of the merged entity is also the sum of the two original valuations. What is the minimum total cost to merge all N startups into one single giant company?
Input Format:
- The first line contains N.
- The second line contains N integers representing the initial valuations.
Output Format:
- A single integer representing the minimum total cost.
Example:
Input:
3
10 2 5
Output:
24
(Explanation: Merge 2 and 5 (cost 7, new set [10, 7]). Merge 10 and 7 (cost 17, new set [17]). Total cost: 7 + 17 = 24.)
Key concepts
greedyheap
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now