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.