Kindly point out the error

this approach is not correct
Correct Approach

Did you run my code over some test cases. ig it gives correct ans