Dividing arrays greedy

i can’t understand the question

u are required to find the way such that the given array elements need to be divided into 2 subaraay each with n eleements ( initially there are 2*n elements)
and after dividng find max and min sum acc to
image

ie subtracting the ith index of both array

so the whole thinking goes into how u will make those arraay( wether sorted or what) such that u obtain maximum and min sum of difference

Hey, I have some curiosity regarding this question
It is not given that n is even.When n is odd,there won’t be any problem in max but there will be choices in min. For example -3,0,10,12,13 here n/2 is 2 so if we make a={-3,10,13} and b={0,12} then min will be 5 but if we make a={-3,13,10} and b={0,12} min will be 4. So how to deal with n as odd.

great to see that u thought beyond the question
but then there are questions which are specifically designed for the purpose
so it will never be so that n is odd
or just in case u get such a q
it would specify you some corner case so we can probably no think of it without reading the question

1 Like

Now it is clear to me. Thanks for the explanation.

1 Like