Above the current cell
if ( isValid ( grid , cellRow - 1 , cellCol ) ) : NEW_LINE INDENT que . appendleft ( [ cellRow - 1 , cellCol ] ) NEW_LINE minDistance [ cellRow - 1 ] [ cellCol ] = min ( minDistance [ cellRow - 1 ] [ cellCol ] , minDistance [ cellRow ] [ cellCol ] + 1 ) NEW_LINE visited [ cellRow - 1 ] [ cellCol ] = 1 NEW_LINE DEDENT