Now find total distance from best meeting point ( x , y ) using Manhattan Distance formula
let distance = 0 ; for ( let i = 0 ; i < ROW ; i ++ ) for ( let j = 0 ; j < COL ; j ++ ) if ( grid [ i ] [ j ] == 1 ) distance += Math . abs ( x - i ) + Math . abs ( y - j ) ; return distance ; }