title: Finding all adjacent elements in a 2D array
body: <p>I am working on a project where at one point I am stuck.</p>
  
  <p>My question is for example I have the following 2D array containing 3 different integers.</p>
  
  <pre><code>2 2 2 2 1 
  1 2 2 2 1 
  3 3 2 3 2 
  3 1 3 3 1 
  1 1 2 3 1 
  1 3 1 3 3 
  </code></pre>
  
  <p>What I want is to find the longest adjacent elements chain of array of any number contained in the array.</p>
  
  <p>Like in the above array the longest chain is of digit 2.</p>
  
  <pre><code>2 2 2 2
    2 2 2
      2
  </code></pre>
  
  <p>Can anyone just guide me as to what I have to do to achieve this goal?</p>