title: Find length of the largest region in Boolean Matrix
body: <p>I got this class who count the biggest island of "1" in the matrix, but he's island concept is <em>"Two cells are said to be connected if they are adjacent to each other horizontally, vertically, or diagonally."</em></p>
  
  <p>I need help to remove the diagonally step.</p>
  
  <pre class="lang-java prettyprint-override"><code>class GFG {
      static int ROW, COL, count;
  
      static boolean isSafe(int[][] M, int row,
                            int col, boolean[][] visited) {
          return ((row &gt;= 0) &amp;&amp; (row &lt; ROW) &amp;&amp; (col &gt;= 0)
                  &amp;&amp; (col &lt; COL) &amp;&amp; (M[row][col] == 1 &amp;&amp;
                  !visited[row][col]));
      }
  
      static void DFS(int[][] M, int row,
                      int col, boolean[][] visited) {
          int[] rowNbr = {-1, -1, -1, 0, 0, 1, 1, 1};
          int[] colNbr = {-1, 0, 1, -1, 1, -1, 0, 1};
  
          visited[row][col] = true;
  
          for (int k = 0; k &lt; 8; k++) {
              if (isSafe(M, row + rowNbr[k], col + colNbr[k], visited)) {
                  count++;
                  DFS(M, row + rowNbr[k], col + colNbr[k], visited);
              }
          }
      }
  
      static int largestRegion(int[][] M) {
          boolean[][] visited = new boolean[ROW][COL];
          int result = 0;
          for (int i = 0; i &lt; ROW; i++) {
              for (int j = 0; j &lt; COL; j++) {
                  if (M[i][j] == 1 &amp;&amp; !visited[i][j]) {
                      DFS(M, i, j, visited);
                      result = Math.max(result, count);
                  }
              }
          }
          return result;
      }
  
      public static void main(String args[]) {
          int M[][] = {{0, 0, 1, 1},
                      {1, 0, 1, 1},
                      {0, 1, 0, 0},
                      {0, 0, 0, 0}};
          ROW = 4;
          COL = 4;
          System.out.println(largestRegion(M));
      }
  }
  </code></pre>
  
  <p>The printed response is 6, but i need he returns 4 i tried everything by now, but i can't resolve. 
  The original post of the algorithm: <a href="https://www.geeksforgeeks.org/find-length-largest-region-boolean-matrix/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/find-length-largest-region-boolean-matrix/</a></p>