title: How can I encompass a region of a 2D Array with a square based on the elements in the array?
body: <p>To provide a simple example, my problem is this:</p>
  <p>I have a <strong>2D array</strong> of <code>1</code>s and <code>0</code>s. Most of the grid is <code>0</code>s, but there are some <code>1</code>s scattered in there. I want to create a square that encompasses all of the 1's without any unnecessary space by finding the indexes of <em>top-left</em> and <em>bottom-right</em> elements of such a square.</p>
  <p>I hope this helps visualize what I'm trying to do:</p>
  <pre><code>       0 1 2 3 4 5 6 7 8 9
  
     A   0 0 0 0 0_0_0_0_0 0
     B   0 0 0 0|0 0 1 0 0|0
     C   0 0 0 0|1 1 1 0 0|0
     D   0 0 0 0|0 0 0 1 1|0
     E   0 0 0 0|1 0 0 0 0|0
     F   0 0 0 0|0_1_0_0_0|0
     G   0 0 0 0 0 0 0 0 0 0
     H   0 0 0 0 0 0 0 0 0 0
  </code></pre>
  <p>So in this case, I would want to find the indexes of <code>B4</code> and <code>F8</code>. I am working in <strong>Java</strong> and would like a solution that does not use Collections.</p>