Rat in a maze Challenge

Can you please check my code… half of the testcases return wrong answer.