I am getting some error

hey @lukharshiv
In solve fun
just a change
public static boolean solve(int maze[][],int x, int y, int sol[][]) {
// if(x==n-1&&y==n-1) {
f(x==n-1&&y==m-1) {
sol[x][y]=1;
return true;
}
// and put this condition
if(x>=n || y>=m ) {
return false ;
}


but your logic is wrong

can you give me a hint for an optimal approach

@lukharshiv
small changes in your code
if(issafe(0,0,maze)==true) {
sol[x][y]=1;
if(solve(maze,x,y+1,sol)){
return true;
}
if(solve(maze,x+1,y,sol)){
return true;
}
sol[x][y]=0;
// Add this line This is a BackTracking
maze[x][y]=0;
}
you can see this