Java program for the above approach
import java . util . * ; class GFG { static final int row = 6 ; static final int col = 7 ; static int [ ] [ ] vis = new int [ row + 1 ] [ col + 1 ] ; static int id ; static int diameter = 0 , length = 0 ; static int x = 0 , y = 0 ;