[LeetCode] Minimum Sensors to Cover Grid

3648. Minimum Sensors to Cover Grid

You are given n × m grid and an integer k.

A sensor placed on cell (r, c) covers all cells whose Chebyshev distance from (r, c) is at most k.

The Chebyshev distance between two cells (r1, c1) and (r2, c2) is max(|r1 − r2|,|c1 − c2|).

Your task is to return the minimum number of sensors required to cover every cell of the grid.

1
2
3
4
5
6
7
8
9
class Solution {
public:
int minSensors(int n, int m, int k) {
int cover = 2 * k + 1;
int row = (n + cover - 1) / cover;
int col = (m + cover - 1) / cover;
return row * col;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/08/17/PS/LeetCode/minimum-sensors-to-cover-grid/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.