#2768
Number of Black Blocks
expert · 1005 · lc medium +32 · verified · 41.6% accepted · 282 likes · top 22%
Description
Two integers m and n describe a 0-indexed m x n grid. A 0-indexed 2D matrix coordinates specifies black cells: coordinates[i] = [x, y] means cell [x, y] is black. All other cells are white.
A block is a 2 x 2 submatrix. A block whose top-left corner is [x, y] (with 0 <= x < m - 1 and 0 <= y < n - 1) covers cells [x, y], [x + 1, y], [x, y + 1], and [x + 1, y + 1].
Return a 0-indexed integer array arr of size 5 such that arr[i] equals the number of blocks containing exactly i black cells.
Example 1:
Input: m = 3, n = 3, coordinates = [[0,0]]
Output: [3,1,0,0,0]
Explanation: The grid looks like this:
Example 2:
There is only 1 block with one black cell, and it is the block starting with cell [0,0].
The other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells.
Thus, we return [3,1,0,0,0].
Example 3:
Input: m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]
Output: [0,2,2,0,0]
Explanation: The grid looks like this:
Example 4:
There are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).
The other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.
Therefore, we return [0,2,2,0,0].
Code
1
2
3