Tap here to switch tabs
Problem
Submissions

Problem: Number of Black Blocks

med
30 min
Try to solve the Number of Black Blocks problem.

Statement

You are given an m by n grid of cells, where some cells are colored black. The black cells are specified by coordinates, where each coordinates[i] = [r, c] marks the cell at row r and column c as black.

Consider every 2×22 \times 2 subgrid (block) fully contained in the grid. For each kk from 00 to 44, compute how many such blocks contain exactly kk black cells.

Return an array ans of length 55 where ans[k] is the number of 2×22 \times 2 blocks with exactly kk black cells.

Constraints:

  • 22 \leq m 105\leq 10^5

  • 22 \leq n 105\leq 10^5

  • 00 \leq coordinates.length 104\leq 10^4

  • coordinates[i].length ==== 22

  • 00 \leq coordinates[i][0] << m

  • 00 \leq coordinates[i][1] << n

  • It is guaranteed that all entries in coordinates are pairwise distinct.

Tap here to switch tabs
Problem
Submissions

Problem: Number of Black Blocks

med
30 min
Try to solve the Number of Black Blocks problem.

Statement

You are given an m by n grid of cells, where some cells are colored black. The black cells are specified by coordinates, where each coordinates[i] = [r, c] marks the cell at row r and column c as black.

Consider every 2×22 \times 2 subgrid (block) fully contained in the grid. For each kk from 00 to 44, compute how many such blocks contain exactly kk black cells.

Return an array ans of length 55 where ans[k] is the number of 2×22 \times 2 blocks with exactly kk black cells.

Constraints:

  • 22 \leq m 105\leq 10^5

  • 22 \leq n 105\leq 10^5

  • 00 \leq coordinates.length 104\leq 10^4

  • coordinates[i].length ==== 22

  • 00 \leq coordinates[i][0] << m

  • 00 \leq coordinates[i][1] << n

  • It is guaranteed that all entries in coordinates are pairwise distinct.