Getting wrong answer

please help…

code:

Hey @rabhi1611
Your approach is incorrect
1
4
1 2 10 20
For this when we want to minimize
[1,10] [2,20] I will form 2 arrays as this and it gives min=1+10=11
For maximum we will form
[1,10] [20,2] ==19+8 =27

Here you need to find minimum and maximum possible value for sum of abs(a[i]-b[i]) for i from 0 to n-1. Approach:

  1. for maximum, pair largest element with smallest, 2nd largest with second smallest and so on.
  2. for mimimum, pair smallest element with 2nd smallest or arr[i] with arr[i+1] for every i=0,2,4,6…
    try implementing this

still getting wrong answer?? code: https://ide.codingblocks.com/s/355197

@rabhi1611

        long long int minimum=0,maximum=0;

Also n is always even
If this resolves ur query then please mark it as resolved :slight_smile: