I got the mistake you are doing here.

(sum(b)-(sum(a)-a[i]))/(n-1);

Here, a[i] is the element which you are trying to remove one by one from the array A to get the array B , but we are not allowed to do this as the second array is already fixed and hence a[i] is also some fixed element.

Hopefully, I had solved your doubt, Please ping me if I didn’t.

You should get different answers from these two cases:

```
2
8
13 1 3 7 11 17 15 5
7 17 19 15 5 9 13
8
3 13 5 15 17 7 11 1
19 7 11 15 9 5 17
```

(the A values are the same each time, and the two sets of B numbers have the same min and max)

from whatever i could decipher we have two unknowns in the eqn:

sum(b)=sum(a)-a[i]+(len(a)-1)* x

the two unkowns are a[i] and x.

to solve for x:

x={sum(b)-sum(a)+a[i]}/{len(a)-1}

we are fixing the value of x by varying a[i].It is very much possible that we get an x for such a[i] which might not even be the right answer!

Hence we must backtrack and check if the value of x in valid or not!