Number of Black Blocks
Real-world version: Marked Cells in Every Two-by-Two WindowThe statement here is our own: the same inputs, outputs and technique.
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.
Examples
Example 1
- Input
- m = 2, n = 2, coordinates = [[0, 0], [0, 1], [1, 0], [1, 1]]
- Output
- [0, 0, 0, 0, 1]
The sheet is a single window and all four of its cells are marked.
Example 2
- Input
- m = 3, n = 3, coordinates = [[1, 1]]
- Output
- [0, 4, 0, 0, 0]
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
- Input
- m = 100000, n = 100000, coordinates = []
- Output
- [9999800001, 0, 0, 0, 0]
Nothing is marked, so every one of the windows holds nothing.
Constraints
- 2 <= m <= 10^5
- 2 <= n <= 10^5
- 0 <= coordinates.length <= 10^4
- coordinates[i].length == 2
- 0 <= coordinates[i][0] <= m - 1
- 0 <= coordinates[i][1] <= n - 1
- No cell is listed twice
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard 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)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Finding 3-Digit Even NumbersReal-world version: Three-Digit Even Numbers From the TilesEasy
- Find the Maximum Number of Elements in SubsetReal-world version: Longest Mirrored Power RunMedium
- Maximum Frequency After Subarray OperationReal-world version: Most Dials Reading k After One NudgeMedium
- Maximum Score with Co-Prime ElementReal-world version: Best Pick Plus What It Leaves CoprimeHard