Maximize sum of consecutive differences in a circular array

algorithm
sorting-algorithms

(Team) #1
Given an array A with values ***a1, a2, a3, a4,..., an*** . Now, arrange all elements of array A such that sum of absolute differences of consecutive elements is maximum, i.e consider after an arrangement the array is ***b1, b2, b3, b4,..., bn*** then maximize `|b1-b2| + |b2-b3| + |b3-b4| + ..... + |bn-1-bn| + |bn-b1|` ***.*** The algorithm presented has a time complexity of O(N log N)

This is a companion discussion topic for the original entry at http://iq.opengenus.org/maximize-sum-of-consecutive-differences-in-a-circular-array/