PMA - Editorial

thanks for sharing this codes , Iā€™m new so Iā€™m gonna try this now

Hey, there are 2 mistakes in the if condition for swapping those elements.

  1. There is no need to put l<h condition as there are no constraints stating that.
  2. Instead of abs(arr[l])!=abs(arr[h]), the condition should be abs(arr[l])>abs(arr[h]).

Could someone please explain how we get this : S+2*(Aj - Ai)

@unbroken711
Thanks for sharing your doubt.

As mentioned in the editorial

S^ā€²=(S_1ā€‹āˆ’| A_iā€‹|+|A_jā€‹ | )-(S_2ā€‹+|A_iā€‹|āˆ’|A_jā€‹|) = S_1-S_2 +2*(|A_j|-|A_i|)

Also S= S_1-S_2

Therefore, S^ā€² = S+2*(|A_j|-|A_i|)

Thank you so much.