ALSO LET ME KNOW HOW TO DIRECTLY SHARE MY CODE FROM CODING BLOCKS IDE.
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in) ;
int row = scan.nextInt() ;
int col = scan.nextInt() ;
char[][] maze = new char[row][col] ;
int[][] solBoard = new int[row][col] ;
for(int i=0;i<row;i++) {
for(int j=0;j<col;j++) {
maze[i][j]=scan.next().charAt(0);
}
}
if(ratmaze(maze,0,0,solBoard))
{
display(solBoard);
}
else
{
System.out.println(-1);
}
}
public static boolean ratmaze(char[][]maze,int row,int col,int[][] solboard)
{
if(row==maze.length-1 && col==maze[0].length-1) {
solboard[row][col]=1;
return true;
}
if(row==-1||row==maze.length||col==-1||col==maze[0].length||maze[row][col]=='x')
{
return false;
}
solboard[row][col]=1;
boolean right=ratmaze(maze,row,col+1,solboard);
boolean down= ratmaze(maze,row+1,col,solboard);
if(right || down) {
return true;
}
else
{
solboard[row][col]=0;
return false;
}
//return true;
}
public static void display(int[][] solBoard){
for(int i = 0 ; i < solBoard.length ; i ++){
for(int j = 0 ; j < solBoard[0].length ; j ++){
System.out.print(solBoard[i][j]+" ") ;
}
System.out.println() ;
}
}
}