Construct Target Array With Multiple Sums
HardLeetCodeConstructive Algorithms
Approach hintTry it first, then revealHide
Work backwards: the largest element was written last, and its previous value is itself minus the sum of the others. Use a max-heap, and replace repeated subtraction with a modulo step so very unbalanced arrays stay fast.