Input: arr[]={1, 2, 3}
Output: 0
Explanation: Choosing 1 and 3 for updating the array, 3-1=2 and 1+1=2. So the updated array becomes arr[]={2, 2, 2}. Minimum possible sum of the absolute difference of pairs is 0+0+0=0.
Input: arr[]={0, 1, 1, 0}
Output: 4
Explanation: Choosing any two elements for updation will lead to increase in total sum of absolute differences. So the sum is 1+1+1+1+0+0=4.
N = 10
arr[] = {8, 3, 6, 11, 5, 2, 1, 7, 10, 4}
Sum of all elements of the array, S=57
So, S/N = 5.7 means if all the elements are converted to 5.7, then the sum of all absolute differences b/w all unique pairs of elements will be minimized i.e, 0.
But converting all elements to 5.7 using the mentioned operation isn't possible.
So, some elements will be 5 and the others will be 6.
Now, the question is how many elements will be 5. Let's say x, then (N-x) will be 6 and in all this process sum will be always be conserved.
=> x*5 + (N-x)*6 = 57
=> -x = 57 - 60 (Putting the value of N as 10 and solving the equation)
-x = -3 => x=3
So, the converted array will be {5, 5, 5, 6, 6, 6, 6, 6, 6, 6}