I have a 2-D array given of size P*Q and I have to answer K questions based on the array. The 2-D array given consists of numbers 0 and 1. For each question, we have to count the maximum size of any square subarray in which no two same elements are adjacent. For example if P=Q=8 and our given array be
00101010
00010101
10101010
01010101
10101010
01010101
10101010
01010101
Then the question Ki allows us to do Ki number of flips(0's to 1 or 1's to 0.)
Here K=4(number of questions)
1 2 0 10001
Output: 7 8 6 8
I have understood that as for K1=1, we can change the value of array index(1,1) to 1 and get a 7*7 sized valid matrix, the output is 7. If we have Ki>=2 our answer will be 8. What I think is that we have to maintain an array ans[k] which stores the maximum size of a square sub matrix which is valid. For this, we can start each index of the original array and traverse through its sub-arrays and count the value of maximum size for flip=i if we start from this index. We have to do this for the subarrays starting from each index and then store the maximum of them in flip[i]. I have problems implementing this as I don't know how to traverse all the sub-arrays for a given index. I'm trying this for so long but still not achieving it. Can anyone please help?