-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2943.cpp
More file actions
28 lines (27 loc) · 914 Bytes
/
2943.cpp
File metadata and controls
28 lines (27 loc) · 914 Bytes
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
class Solution {
public:
int maximizeSquareHoleArea(int n, int m, vector<int>& hBars, vector<int>& vBars) {
sort(hBars.begin(), hBars.end());
sort(vBars.begin(), vBars.end());
int maxH = 0;
int maxV = 0;
int index = 0;
while (index < hBars.size()) {
int left = index;
while (index + 1 < hBars.size() && hBars[index] + 1 == hBars[index + 1]) index++;
int length = index - left + 2;
maxH = max(maxH, length);
index++;
}
index = 0;
while (index < vBars.size()) {
int left = index;
while (index + 1 < vBars.size() && vBars[index] + 1 == vBars[index + 1]) index++;
int length = index - left + 2;
maxV = max(maxV, length);
index++;
}
int size = max(1, min(maxH, maxV));
return size * size;
}
};