My code is working fine in eclipse . But test cases are failing due to rum time error . Can you tell me which line is leading to run time error ?
Here is my code :
import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
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.print(-1) ;
}
public static boolean ratMaze(char[][] maze , int row , int col , int[][] solBoard){
if(row == maze.length){
return false ;
}
if(col == maze[0].length){
return false ;
}
if(maze[row][col] == 'X'){
return false ;
}
if(row == maze.length -1 && col == maze[0].length-1){
solBoard[row][col] = 1 ;
return true ;
}
//boolean res = false ;
solBoard[row][col] = 1 ;
boolean right = ratMaze(maze , row , col+1 , solBoard) ;
if(!right){
boolean down = ratMaze(maze,row+1,col,solBoard) ;
if(right || down){
return true ;
}
else{
solBoard[row][col] = 0 ;
return false ;
}
}
return right ;
}
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() ;
}
}
}