Skip to content

Commit f5c0b97

Browse files
authored
Create maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.cpp
1 parent 231235b commit f5c0b97

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time: O(hlogh + wlogw)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int maxArea(int h, int w, vector<int>& horizontalCuts, vector<int>& verticalCuts) {
7+
static const int MOD = 1e9 + 7;
8+
return max_len(h, &horizontalCuts) * max_len(w, &verticalCuts) % MOD;
9+
}
10+
11+
private:
12+
uint64_t max_len(int l, vector<int> *cuts) {
13+
sort(begin(*cuts), end(*cuts));
14+
l = max((*cuts)[0] - 0, l - cuts->back());
15+
for (int i = 1; i < cuts->size(); ++i) {
16+
l = max(l, (*cuts)[i] - (*cuts)[i - 1]);
17+
}
18+
return l;
19+
}
20+
};

0 commit comments

Comments
 (0)