Given a list of integers, how to find the sum of the differences of all possible pairs of numbers ?
For example if the number are $3,1,2$ then, answer should be $\lvert 3-1 \rvert + \lvert 3 -2 \rvert + \lvert 1-2 \rvert = 2 + 1 + 1 = 4 $
Suggest a suitable algorithm for this.