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 prints 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 .
def solveMaze ( maze ) : NEW_LINE INDENT sol = [ [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] ] NEW_LINE if ( solveMazeUtil ( maze , 0 , 0 , sol ) == False ) : NEW_LINE INDENT print ( " Solution ▁ doesn ' t ▁ exist " ) NEW_LINE return False NEW_LINE DEDENT printSolution ( sol ) NEW_LINE return True NEW_LINE DEDENT