#3801

Minimum Cost to Merge Sorted Lists

master · 1885 · lc hard +32 · 34% accepted · 41 likes · top 11%

Description

Given a 2D integer array lists of non-decreasingly sorted arrays, repeatedly select two arrays a and b, incur a merge cost of len(a) + len(b) + abs(median(a) - median(b)) (the median of an even-length array is the left-middle element), replace both with their merged sorted array, and continue until one array remains; return the minimum total merge cost.

Code

1
2
3