-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11_Count_Covered_Buildings.cpp
More file actions
52 lines (42 loc) · 1.14 KB
/
Copy path11_Count_Covered_Buildings.cpp
File metadata and controls
52 lines (42 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// 3531. Count Covered Buildings
class Solution
{
public:
int countCoveredBuildings(int n, vector<vector<int>> &buildings)
{
unordered_map<int, vector<int>> rowMap;
unordered_map<int, vector<int>> colMap;
// Build maps
for (auto &b : buildings)
{
rowMap[b[0]].push_back(b[1]);
colMap[b[1]].push_back(b[0]);
}
int result = 0;
for (auto &b : buildings)
{
int x = b[0], y = b[1];
bool left = false, right = false;
bool up = false, down = false;
// Check row for left/right
for (int col : rowMap[x])
{
if (col < y)
left = true;
if (col > y)
right = true;
}
// Check column for up/down
for (int row : colMap[y])
{
if (row < x)
up = true;
if (row > x)
down = true;
}
if (left && right && up && down)
result++;
}
return result;
}
};