How to convert a 2D array to 1D array with the value as the index?
<p>I have a 2D array that gets dynamically created by any integer N. Initially, I need to set all values in the array to a value that represents it being "uninitialized" where I use the number "-1". However, I want to convert this 2D array to a 1D array and assign every value to be equal to its index in the new 1D array. </p>

<pre><code>public class Percolation {

private int[][] id;
private int[] array1D;
private int blocked = -1;   //a number that doesn't exist in the array

// create N-by-N grid, with all sites blocked
public Percolation(int N){

    id = new int[N][N];
    for (int k = 0; k &lt; N; k++)
    { for (int i = 0; i &lt; N; i++) id[k][i] = blocked; } 
}


// open site (row i, column j) if it is not already
public void open(int i, int j){


}
</code></pre>

<p>In the open method it should change the value at the given indexes to be the corresponding index in a 1D array. For example:</p>

<blockquote>
  <p>[-1] [-1]</p>
  
  <p>[-1] [-1]</p>
</blockquote>

<p>Would then become:</p>

<blockquote>
  <p>[0] [1] [2] [3]</p>
</blockquote>

<p>Unfortunately, since this is homework I'm unsure how I can share the grid size "N" to be able to create a new 1D array with the indexes as the values. </p>
