Code Room
CodingMediumcod-g1285
Subject HeapsLevel Entry–Mid~16 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A finance team consolidates expense reports at quarter end. Merging two reports produces one report whose line count is the sum of the two, and the merge costs that many line reviews (every line gets re-checked). Reports can be merged in any order, two at a time, until one remains. Given the line counts of the initial reports, return the minimum total number of line reviews. Zero or one report needs no merging, so the cost is 0. Example: counts = [4, 3, 2, 6] gives 29.

Implement
min_merge_cost(counts: list[int]) → int
Examples
in[[4,3,2,6]]out29
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.