Skip to content

Commit 31e6607

Browse files
committed
Solution as on 05-07-2022 07:30 am
1 parent dfe9504 commit 31e6607

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// 1465.✅ Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
2+
3+
class Solution
4+
{
5+
public:
6+
int maxArea(int h, int w, vector<int> &horizontalCuts, vector<int> &verticalCuts)
7+
{
8+
9+
int hmax = 0;
10+
int vmax = 0;
11+
12+
// horizontalCuts.insert(horizontalCuts.begin(),0);
13+
// verticalCuts.insert(verticalCuts.begin(),0);
14+
15+
horizontalCuts.push_back(0);
16+
horizontalCuts.push_back(h);
17+
18+
verticalCuts.push_back(0);
19+
verticalCuts.push_back(w);
20+
21+
// for(auto x : horizontalCuts)
22+
// cout<<x<<" ";
23+
// cout<<endl;
24+
25+
// for(auto y : verticalCuts)
26+
// cout<<y<<" ";
27+
// cout<<endl;
28+
29+
sort(horizontalCuts.begin(), horizontalCuts.end());
30+
sort(verticalCuts.begin(), verticalCuts.end());
31+
32+
for (int i = 1; i < horizontalCuts.size(); ++i)
33+
{
34+
hmax = max(hmax, horizontalCuts[i] - horizontalCuts[i - 1]);
35+
}
36+
37+
for (int i = 1; i < verticalCuts.size(); ++i)
38+
{
39+
vmax = max(vmax, verticalCuts[i] - verticalCuts[i - 1]);
40+
}
41+
42+
return (1LL * vmax * hmax) % 1000000007;
43+
}
44+
};

0 commit comments

Comments
 (0)