title: Identify consecutive repetition in two-dimensional array [C]
body: <p>I have a 2-dimensional array that looks like this:</p>
  
  <pre><code>1 1 0 0 1
  1 0 1 1 0
  0 0 1 1 0
  1 1 0 1 1
  0 0 1 1 1
  </code></pre>
  
  <p>I'm trying to figure out a way to identify the longest contiguous chain of 1's going either across or down. In this case, it starts at column 4, row 2, and its length is 4, going down.</p>
  
  <p>I was thinking of using recursion, but I'm running into some issues keeping track of position, especially when encountering a 0. </p>
  
  <p>So far, I have something along the lines of this (for checking across only):</p>
  
  <pre><code>main() {
      ...
      for(i = 0; i &lt; n; i++)
        for(j = 0; j &lt; n; j++)
          if (G[i][j] == 1) {
            CheckAcross(i, j, n);
          }
      ...
  }
  
  void CheckAcross (int i, int j, int n) {
       if (i &lt; 0 || i &gt;= n || j &lt; 0 || j &gt;= n) return; // outside of grid
       if (G[i][j] == 0 ) return; //0 encountered
       G[i][j] = WordCount + 1;
       CheckAcross(i, j + 1, n);
  
  }
  </code></pre>
  
  <p>where <code>G[][]</code> is the 2-dimensional array containing the 1's and 0's, <code>n</code> is the number of rows/columns, <code>i</code> is the row number and <code>j</code> is the column number.</p>
  
  <p>Thanks for any assistance in advance!</p>