Logic not working

Maam / Sir
I have tried to write the logic to get the rightmost way in this question but my ouput is not coming.
Please give me a hint to check if the path travelled by rat is rightmost or not.

If
destination is reached print the solution matrix .
Else .
a) Mark current cell in solution matrix as 1.
b) Move forward in the horizontal direction and recursively check if this move leads to a solution.
c) If the move chosen in the above step doesn’t lead to a solution then move down and check if this move leads to a solution.
d) If none of the above solutions works then unmark this cell as 0 (BACKTRACK) and return false

Maam this method will print 4 solutions but we have to find the rightmost question acc. to question.

you can see this: