Java Program to find the maximum distance from a 0 - cell to a 1 - cell
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int maxDistance ( int [ ] [ ] grid ) { Vector < pair > one = new Vector < pair > ( ) ; int M = grid . length ; int N = grid [ 0 ] . length ; 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 ) ) ; } }