Correct Solution

Hi,

Even the solution given in the editorial section of solution is not succeeding all the testcases; only testcase 0 and 4 are success.
Please look into it and provide the correct solution.

Thanks!