Dividing array problem not clear

Giving wrong answer.
I have first sorted the array , then,
For minimum element apply formula for adjacent elements and incrementing by 2.
For maximum element, take two pointers i=0 & i=n-1 apply formula and increment and decrement the pointer by 2 respectively.
Please verify the approach, correct me if wrong.

Hi @abhir26

There is a very simple approach to this question. Minsum is obtained when adjacent elements are present in different arrays. And maxsum is obtained when after sorting first n/2 element remain in array a sorted in ascending order and last n/2 elements in array b sorted in descending order then take the difference of both these arrays to get maxsum.

Code for Reference : https://ide.codingblocks.com/s/194145

Also there is no need to multiply with n/4 as you have done in your code.

Hope it Helps.

@abhir26

If your query is resolved , please mark it as resolved.

Thanks.