There is a grid of size m * n. At every cell in the grid there is a number denoting color of flower. A cell is said to be connected if shares a side with aother. How to find size of maximum connected grid containing only 2 colours.
In the worst case the number of colours can be m*n.
1<= m <= 2000
1<= n <=2000
Example :
Input -
1 2 3 1
1 1 1 1
2 2 2 2
Output -
11
Explanation -
All the cells except the one having 3.