Trains the technique from
LeetCode 3212Count Submatrices With Equal Frequency of X and YThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A board is given as grid, each cell holding 'X', 'Y' or '.'.
A corner block is a rectangle of cells whose top-left cell is the board's own top-left cell. A corner block balances when it holds as many 'X' marks as 'Y' marks and holds at least one 'X'.
Return how many corner blocks balance.
Example 1
Each corner block is named by its bottom-right cell. Those whose X and Y counts come out level, with at least one X present, are the ones counted.
Example 2
The block ending at the first cell holds one X and no Y, so it does not balance. The block covering both cells holds one of each, so it does.
Example 3
The only block holds no X at all, so nothing balances.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def number_of_submatrices(grid: list[list[str]]) -> int:public int numberOfSubmatrices(char[][] grid)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.