board where every cell is 'X', 'Y' or '.'. Consider the rectangles that start at the top-left cell (0, 0) and end at any cell (i, j).
Count how many of these rectangles satisfy both:
- they contain as many 'X' cells as 'Y' cells;
- they contain at least one 'X'.board=[['X', 'Y', '.'], ['Y', '.', '.']] → 3
The rectangles ending at (0, 1), (0, 2) and (1, 0) qualify, each with one X and one Y. The rest have an unmatched X or an extra Y.
board=[['.', 'Y'], ['.', 'X']] → 1
Only the whole board has equal counts (one of each) and at least one X.
board=[['Y', 'X']] → 1
board=[['X', 'Y', '.'], ['Y', '.', '.']]
3
Run checks the first 3 tests in your browser. Submit checks all 48 tests on the server, hidden ones included.