Minimum cost to merge reports

Write codeMedium16 min

Your task

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.

Examples

min_merge_cost(counts: list[int]) -> int
Example 1
Inputmin_merge_cost([4, 3, 2, 6])
Output29