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.
- There is no need to put l<h condition as there are no constraints stating that.
- 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.