Official algorithmic problem description and constraints.
The alternating sum of an array π΄ of length π is defined to be βπ=1π(β1)π+1π΄π
β
If you expand it out, this is the expression π΄1βπ΄2+π΄3βπ΄4+β¦+(β1)π+1π΄π.
You're given an array π΄ containing π integers. You can rearrange this array however you like.
Find the maximum possible value of the alternating sum of π΄ after rearrangement.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.