This function solves the Maze problem using Backtracking . It mainly uses solveMazeUtil ( ) to solve the problem . It returns false if no path is possible , otherwise return true and print the path in the form of 1 s . Please note that there may be more than one solutions , this function prints one of the feasible solutions .
function solveMaze ( maze ) { let sol = [ [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] ] ; if ( solveMazeUtil ( maze , 0 , 0 , sol ) == false ) { document . write ( " " ) ; return false ; } printSolution ( sol ) ; return true ; }