#3212

Count Submatrices With Equal Frequency of X and Y

specialist · 860 · lc medium +31 · 51.5% accepted · 161 likes · top 41%

Description

You are given a 2D character matrix grid where each cell is 'X', 'Y', or '.'.

Count the submatrices satisfying all of:

- They include grid[0][0].

- They contain equal numbers of 'X' and 'Y'.

- They contain at least one 'X'.

Code

1
2
3