Algorithm · Squarepoint · Hard
Let nums be an odd-length array of positive integers. Consider deleting exactly one occurrence of one element. The elements that remain must be split into two-element pairs, with no element left over or reused. If a pair contains x and y, its cost is $$\lvert x - y \rvert$$, and the total cost of a pairing is the sum of the costs of all its pairs. For every possible deletion, pair the surviving elements in the way that minimizes this total cost. Let the globally optimal cost…
Checking your access…