In an n×n array of unit squares, two squares are said to be adjacent if they share an edge.
For example, for a 2×2 array, there are essentially only three cases to consider as shown below. In this case, the minimum value is 6 and the maximum value is 8.