C # program to find the maximum distance from a 0 - cell to a 1 - cell
using System ; using System . Collections . Generic ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int maxDistance ( int [ , ] grid ) { List < pair > one = new List < pair > ( ) ; int M = grid . GetLength ( 0 ) ; int N = grid . GetLength ( 1 ) ; int ans = - 1 ; for ( int i = 0 ; i < M ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) { if ( grid [ i , j ] == 1 ) one . Add ( new pair ( i , j ) ) ; } }