Skip to content

Commit f5f3627

Browse files
committed
2257. Count Unguarded Cells in the Grid: RETRY
1 parent 88b6d92 commit f5f3627

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,3 +1707,4 @@ mod s2250_count_number_of_rectangles_containing_each_point;
17071707
mod s2251_number_of_flowers_in_full_bloom;
17081708
mod s2255_count_prefixes_of_a_given_string;
17091709
mod s2256_minimum_average_difference;
1710+
mod s2257_count_unguarded_cells_in_the_grid;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* [2257] Count Unguarded Cells in the Grid
3+
*
4+
* You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] represent the positions of the i^th guard and j^th wall respectively.
5+
* A guard can see every cell in the four cardinal directions (north, east, south, or west) starting from their position unless obstructed by a wall or another guard. A cell is guarded if there is at least one guard that can see it.
6+
* Return the number of unoccupied cells that are not guarded.
7+
*
8+
* Example 1:
9+
* <img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/example1drawio2.png" style="width: 300px; height: 204px;" />
10+
* Input: m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]]
11+
* Output: 7
12+
* Explanation: The guarded and unguarded cells are shown in red and green respectively in the above diagram.
13+
* There are a total of 7 unguarded cells, so we return 7.
14+
*
15+
* Example 2:
16+
* <img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/example2drawio.png" style="width: 200px; height: 201px;" />
17+
* Input: m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]]
18+
* Output: 4
19+
* Explanation: The unguarded cells are shown in green in the above diagram.
20+
* There are a total of 4 unguarded cells, so we return 4.
21+
*
22+
*
23+
* Constraints:
24+
*
25+
* 1 <= m, n <= 10^5
26+
* 2 <= m * n <= 10^5
27+
* 1 <= guards.length, walls.length <= 5 * 10^4
28+
* 2 <= guards.length + walls.length <= m * n
29+
* guards[i].length == walls[j].length == 2
30+
* 0 <= rowi, rowj < m
31+
* 0 <= coli, colj < n
32+
* All the positions in guards and walls are unique.
33+
*
34+
*/
35+
pub struct Solution {}
36+
37+
// problem: https://leetcode.com/problems/count-unguarded-cells-in-the-grid/
38+
// discuss: https://leetcode.com/problems/count-unguarded-cells-in-the-grid/discuss/?currentPage=1&orderBy=most_votes&query=
39+
40+
// submission codes start here
41+
42+
impl Solution {
43+
pub fn count_unguarded(m: i32, n: i32, guards: Vec<Vec<i32>>, walls: Vec<Vec<i32>>) -> i32 {
44+
0
45+
}
46+
}
47+
48+
// submission codes end
49+
50+
#[cfg(test)]
51+
mod tests {
52+
use super::*;
53+
54+
#[test]
55+
#[ignore]
56+
fn test_2257_example_1() {
57+
let m = 4;
58+
let n = 6;
59+
let guards = vec![vec![0, 0], vec![1, 1], vec![2, 3]];
60+
let walls = vec![vec![0, 1], vec![2, 2], vec![1, 4]];
61+
62+
let result = 7;
63+
64+
assert_eq!(Solution::count_unguarded(m, n, guards, walls), result);
65+
}
66+
67+
#[test]
68+
#[ignore]
69+
fn test_2257_example_2() {
70+
let m = 3;
71+
let n = 3;
72+
let guards = vec![vec![1, 1]];
73+
let walls = vec![vec![0, 1], vec![1, 0], vec![2, 1], vec![1, 2]];
74+
75+
let result = 4;
76+
77+
assert_eq!(Solution::count_unguarded(m, n, guards, walls), result);
78+
}
79+
}

0 commit comments

Comments
 (0)