Above the current cell
if ( isValid ( grid , cellRow - 1 , cellCol ) ) { que . push ( make_pair ( cellRow - 1 , cellCol ) ) ; minDistance [ cellRow - 1 ] [ cellCol ] = min ( minDistance [ cellRow - 1 ] [ cellCol ] , minDistance [ cellRow ] [ cellCol ] + 1 ) ; visited [ cellRow - 1 ] [ cellCol ] = 1 ; }