#3212
Count Submatrices With Equal Frequency of X and Y
medium · 51.5% accepted · 161 likes · top 41%
array · matrix · prefix sum
Description
Given a 2D character matrix grid, where grid[i][j] is either 'X', 'Y', or '.', return the number of submatrices that contain:
- grid[0][0]
- an equal frequency of 'X' and 'Y'.
- at least one 'X'.
Solution