int[][] arr = new int[][] { {0, 0, 0, 0}, {1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 1} };
int prev_len = 0;
int index = 0;
for(int i = 0; i < arr.length; i++)
{
int sq_rt = (int) Math.sqrt(arr[0].length);
if(Math.sqrt(arr[0].length) - sq_rt == 0)
{
int count = 0;
for(int j = 0; j < arr[i].length; j++)
{
if(arr[i][j] == 1)
{
count++;
if(count == arr[i].length)
{
prev_len = arr[i].length;
index = i;
}
}
else
{
break;
}
}
}
}
System.out.println("The largest square sub-array containing 1s is at index " +index+ " and its length is " +prev_len);