Check if the upper move is valid
if ( isSafe ( row - 1 , col , m , n , visited ) ) { path += ' ' ; printPathUtil ( row - 1 , col , m , n , visited ) ; path = path . substring ( 0 , path . length - 1 ) ; }