Why my testcase 2 is not passing

I think you meant

mx=max(abs(sum[i]-x),mx);