# Abs(sum of differences of elements in a sorted array) = array.Max()-array.Min() Why?

I just found out by luck that

 Abs(sum of differences of elements in a sorted array) = array.Max()-array.Min()


For example, Consider a sorted array, {1 43 65 97 98 99 101}

Abs(1-43-55-97-98-99-101)= 101-1

Does anyone know why?

• Yes. Just write it out... – Gilles 'SO- stop being evil' Oct 1 '16 at 22:03
• Higher character encodes higher value. b - a = -(a - b), since array is in ascending order than abs is not needed, simple minus suffice. But why it works for more elements? c - b + b - a = -(a - b + b - c) And this just encodes consecutive differences of sorted elements. I hope you see the pattern. – Evil Oct 1 '16 at 22:07
• Re: "Abs(1-43-55-97-98-99-101)= 101-1": This is not true. – ruakh Oct 1 '16 at 23:40
• What does this have to do with computer science, except that you chose to say "array" rather than "sequence of integers"? – David Richerby Oct 2 '16 at 9:37

• That's an excellent explanation. For completeness, you should probably say "telescoping sum" and observe that, in $97-81+81-45+45-7$, everything except the first and last term cancels. – David Richerby Oct 2 '16 at 9:40