You are given a rectangular field divided into square cells. Each cell contains a letter. A square with vertices in the centers of four cells is called valid if those four cells are distinct and all contain the same letter. For example, the following field contains two valid squares:
ABA
BAB
ABA
One has vertices in the centers of the following squares:
A.A
...
A.A
Another has vertices in the centers of the following cells:
.B.
B.B
.B.
You are given a String[] field. The j-th character of the i-th element of field is the letter contained in the cell at row i, column j. Return the number of distinct valid squares in the field. Two squares are distinct if one has a vertex in a cell where the other does not.
|