can u please explain how the given output came
Dividing array problem
hey @mikkyimran it is mentioned in the question that you have remove n/2 elements from A and add them to B and after doing that you can rearrange the elements in any order and you have to find minimum and maximum value of the difference between the array
A = 12, -3, 10, 0
For Maximum difference
A = 12,10
B = -3, 0
Diff (12 - (-3)) + (10 - 0) = 25
For Minimum difference
A = 0, 12
B = -3, 10
Diff = (0 - (-3)) + (12 - 10) = 5.
how to approach this question?
sort the array, in case of minimum difference the adjacent elements will belong to a, b and in the case of maximum difference the first half subarry will be a, second half will be b
1 Like
thanks sir! i was able to solve it
Happy to help 