forked from garvit-bhardwaj/Leetcode-Problems-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Maximum Area of a Piece of Cake After Horizontal and Vertical …
…Cuts.cpp
- Loading branch information
1 parent
a374542
commit 203bba6
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
}; |