RAT IN A MAZE problem

public class Main {
static int n;
public static void printsol(int sol[][]){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
System.out.print(" “+sol[i][j] +” ");
System.out.println();

}

}
public static boolean issafe(int maxe[][],int x,int y){
return(x>=0 && x<n && y>=0 && y<n && maxe[x][y]==1);
}
public static boolean solvemazeutil(int maze[][],int x,int y,int sol){
if(x==n-1 && y==n-1){
sol[x][y]=1;
return true;
}
if(issafe(maze,x,y)==true){
sol[x][y]=1;
if(solvemazeutil(maze,x+1,y,sol))
return true;
if(solvemazeutil(maze,x,y+1,sol))
return true;
sol[x][y]=0;
return false;}return false;}

public static boolean solveMaze(int maze[][]){
int sol[][]=new int[n][n];
if(solvemazeutil(maze,0,0,sol)==false){
return false;
}
printsol(sol);
return true;
}

public static void main(String args[]) {

int maze[][] = { { 1, 0, 0, 0 }, 
                 { 1, 1, 0, 1 }, 
                 { 0, 1, 0, 0 }, 
                 { 1, 1, 1, 1 } }; 

n = maze.length; 

solveMaze(maze);

}
}
what is problem in my code

@Sweta,
In your maze array, 1 is safe or blocked position?

1 is safe in maze problem

@Sweta,
https://ide.codingblocks.com/s/167946 This is the corrected code. Your code was correct. Only input format was missing. Also I went right first and then down. Instead of the other way around. Also, array input is not necessarily a square matrix

@Sweta,
Please mark your doubts as resolved in your course’s “Ask Doubt” section, if your doubt is resolved. :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.