Given an array of n elements. Consider array as circular array i.e element after an is a1. The task is to find maximum sum of the difference between consecutive elements with rearrangement of array element allowed i.e after rearrangement of element find |a1 – a2| + |a2 – a3| + …… + |an – 1– an| + |an – a1|.
The first line of input contains an integer T denoting the number of test cases. Each test case contains the number of elements in the array a as n and next line contains space separated n elements in the array a.
Print an integer which denotes the maximized sum.
4 2 1 8
10 12 15
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.