When i am using using the same code i am getting more than 2 solutions and in which some are wrong as well

after checking for diagonal you forgot to initialize x and y to i and j resp.

//checking f0or the right diagnol
        x=i;
        y=j;

i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved :grinning:
if you have more doubts regarding this feel free to ask