3648. Minimum Sensors to Cover Grid Medium

@problem@discussion
#Math



1/**
2 * [3648] Minimum Sensors to Cover Grid
3 *
4 * You are given n × m grid and an integer k.
5 * A sensor placed on cell (r, c) covers all cells whose Chebyshev distance from (r, c) is at most k.
6 * The Chebyshev distance between two cells (r1, c1) and (r2, c2) is max(|r1 - r2|,|c1 - c2|).
7 * Your task is to return the minimum number of sensors required to cover every cell of the grid.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">n = 5, m = 5, k = 1</span>
12 * Output: <span class="example-io">4</span>
13 * Explanation:
14 * Placing sensors at positions (0, 3), (1, 0), (3, 3), and (4, 1) ensures every cell in the grid is covered. Thus, the answer is 4.
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">n = 2, m = 2, k = 2</span>
19 * Output: <span class="example-io">1</span>
20 * Explanation:
21 * With k = 2, a single sensor can cover the entire 2 * 2 grid regardless of its position. Thus, the answer is 1.
22 * </div>
23 *  
24 * Constraints:
25 * 
26 * 	1 <= n <= 10^3
27 * 	1 <= m <= 10^3
28 * 	0 <= k <= 10^3
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/minimum-sensors-to-cover-grid/
34// discuss: https://leetcode.com/problems/minimum-sensors-to-cover-grid/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn min_sensors(n: i32, m: i32, k: i32) -> i32 {
40        0
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_3648() {
52    }
53}
54

Back
© 2026 bowen.ge All Rights Reserved.