Skip to content

Commit

Permalink
Create Maximum Area of a Piece of Cake After Horizontal and Vertical …
Browse files Browse the repository at this point in the history
…Cuts.cpp
  • Loading branch information
EmanMohamed36 authored Oct 1, 2022
1 parent a374542 commit 203bba6
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {
public:
int maxArea(int h, int w, vector<int>& hC, vector<int>& vC) {
hC.push_back(h);
sort(hC.begin(), hC.end());
int maxh = hC[0];
for(int i=1; i<hC.size(); i++){
maxh = max(maxh, hC[i] - hC[i-1]);
}

vC.push_back(w);
sort(vC.begin(), vC.end());
int maxv = vC[0];
for(int i=1; i<vC.size(); i++){
maxv = max(maxv, vC[i] - vC[i-1]);
}

return (1LL*maxh*maxv) % 1000000007; //1LL used to make the product long long or integer sign overflow will occur.
}
};

0 comments on commit 203bba6

Please sign in to comment.