The sum of difference in all pairs in an array

221 Views Asked by At

I have an array of 2n distinct non-negative integers, the goal is to find if it's possible to put all integers into pairs such that the sum of the absolute difference of all pairs is equal to a specific number x.
Example: [1, 2, 3, 5, 8, 10] If x=5, it is possible because the total absolute difference of (1, 2), (3, 5), and (8, 10) is 5.
If x=10 it is not possible.