Passed the sample test case but in others wrong anser

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

ur approach would not work for n == 1 and also it is not required to parition the array element at the time u add values

but n cannot be 1,i did what you are telling

still wrong answer please see

did u refer to this code?

did not understand the question properly. thanks