3531. Count Covered Buildings Medium

@problem@discussion
#Array#Hash Table#Sorting



1/**
2 * [3531] Count Covered Buildings
3 *
4 * You are given a positive integer n, representing an n x n city. You are also given a 2D grid buildings, where buildings[i] = [x, y] denotes a unique building located at coordinates [x, y].
5 * A building is covered if there is at least one building in all four directions: left, right, above, and below.
6 * Return the number of covered buildings.
7 *  
8 * <strong class="example">Example 1:
9 * <img src="https://assets.leetcode.com/uploads/2025/03/04/telegram-cloud-photo-size-5-6212982906394101085-m.jpg" style="width: 200px; height: 204px;" />
10 * <div class="example-block">
11 * Input: <span class="example-io">n = 3, buildings = [[1,2],[2,2],[3,2],[2,1],[2,3]]</span>
12 * Output: <span class="example-io">1</span>
13 * Explanation:
14 * 
15 * 	Only building [2,2] is covered as it has at least one building:
16 * 	
17 * 		above ([1,2])
18 * 		below ([3,2])
19 * 		left ([2,1])
20 * 		right ([2,3])
21 * 	
22 * 	
23 * 	Thus, the count of covered buildings is 1.
24 * </div>
25 * <strong class="example">Example 2:
26 * <img src="https://assets.leetcode.com/uploads/2025/03/04/telegram-cloud-photo-size-5-6212982906394101086-m.jpg" style="width: 200px; height: 204px;" />
27 * <div class="example-block">
28 * Input: <span class="example-io">n = 3, buildings = [[1,1],[1,2],[2,1],[2,2]]</span>
29 * Output: <span class="example-io">0</span>
30 * Explanation:
31 * 
32 * 	No building has at least one building in all four directions.
33 * </div>
34 * <strong class="example">Example 3:
35 * <img src="https://assets.leetcode.com/uploads/2025/03/16/telegram-cloud-photo-size-5-6248862251436067566-x.jpg" style="width: 202px; height: 205px;" />
36 * <div class="example-block">
37 * Input: <span class="example-io">n = 5, buildings = [[1,3],[3,2],[3,3],[3,5],[5,3]]</span>
38 * Output: <span class="example-io">1</span>
39 * Explanation:
40 * 
41 * 	Only building [3,3] is covered as it has at least one building:
42 * 	
43 * 		above ([1,3])
44 * 		below ([5,3])
45 * 		left ([3,2])
46 * 		right ([3,5])
47 * 	
48 * 	
49 * 	Thus, the count of covered buildings is 1.
50 * </div>
51 *  
52 * Constraints:
53 * 
54 * 	2 <= n <= 10^5
55 * 	1 <= buildings.length <= 10^5 
56 * 	buildings[i] = [x, y]
57 * 	1 <= x, y <= n
58 * 	All coordinates of buildings are unique.
59 * 
60 */
61pub struct Solution {}
62
63// problem: https://leetcode.com/problems/count-covered-buildings/
64// discuss: https://leetcode.com/problems/count-covered-buildings/discuss/?currentPage=1&orderBy=most_votes&query=
65
66// submission codes start here
67
68impl Solution {
69    pub fn count_covered_buildings(n: i32, buildings: Vec<Vec<i32>>) -> i32 {
70        0
71    }
72}
73
74// submission codes end
75
76#[cfg(test)]
77mod tests {
78    use super::*;
79
80    #[test]
81    fn test_3531() {
82    }
83}
84

Back
© 2026 bowen.ge All Rights Reserved.