Skip to content

Commit dab3fd0

Browse files
authored
Create Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts.java
1 parent 57f2684 commit dab3fd0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) {
3+
Arrays.sort(horizontalCuts);
4+
Arrays.sort(verticalCuts);
5+
int n = horizontalCuts.length;
6+
int m = verticalCuts.length;
7+
long maxHeight = Math.max(horizontalCuts[0], h - horizontalCuts[n - 1]);
8+
for (int i = 1; i < n; i++) {
9+
maxHeight = Math.max(maxHeight, horizontalCuts[i] - horizontalCuts[i - 1]);
10+
}
11+
long maxWidth = Math.max(verticalCuts[0], w - verticalCuts[m - 1]);
12+
for (int i = 1; i < m; i++) {
13+
maxWidth = Math.max(maxWidth, verticalCuts[i] - verticalCuts[i - 1]);
14+
}
15+
return (int) ((maxWidth * maxHeight) % (1000000007));
16+
}
17+
}

0 commit comments

Comments
 (0)