Trains the technique from
LeetCode 2768Number of Black BlocksThis 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 sheet has m rows and n columns of cells, numbered from zero. The cells listed in coordinates, each [row, column], are marked; the rest are blank, and no cell is listed twice.
A window is any two-by-two square of neighbouring cells, so there are (m - 1) * (n - 1) of them.
Return a list of five counts: how many windows hold exactly 0 marked cells, then exactly 1, and so on up to exactly 4.
Example 1
The sheet is a single window and all four of its cells are marked.
Example 2
The middle cell of a three by three sheet sits in all four windows, so each of them holds exactly one marked cell.
Example 3
Nothing is marked, so every one of the windows holds nothing.
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 count_black_blocks(m: int, n: int, coordinates: list[list[int]]) -> list[int]:public long[] countBlackBlocks(int m, int n, int[][] coordinates)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.