Minimum Operations to Make Array Equal

Asked at D. E. Shaw · Coding Questions · Difficulty: Hard · Last asked Jul 15, 2026

From an array `source` of `n` integers, in a single operation, choose any even-length subarray. Alternately add and subtract 1 from each element of the subarray from left to right. For example, for `source = [1, 2, 3, 4, 5, 6]` the subarray `[3, 4, 5, 6]` can be chosen and made `[3+1, 4-1, 5+1, 6-1] = [4, 3, 6, 5]`. Then `source = [1, 2, 4, 3, 6, 5]`.

Loading the problem…