https://algo.monster/problems/amazon_oa_storage_optimization
Leetcode: https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/
Can you add the leet code link to this page? Thanks.
class Solution {
public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) {
long M = 1000000007L;
return (int)(((long)longest(horizontalCuts, h) * (long)longest(verticalCuts, w)) % M);
}
private int longest(int[] arr, int end) {
Arrays.sort(arr);
int max = arr[0];
int n = arr.length;
for (int i = 1; i < n; i++) {
int gap = arr[i] - arr[i - 1];
max = Math.max(gap, max);
}
if (end > 100000) {
end = 100000;
}
max = Math.max(end - arr[n-1], max);
return max;
}
}
class Solution {
public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) {
long M = 1000000007L;
return (int)((longest(horizontalCuts, h) * longest(verticalCuts, w)) % M);
}
private long longest(int[] arr, int end) {
Arrays.sort(arr);
long max = arr[0];
int n = arr.length;
for (int i = 1; i < n; i++) {
long gap = arr[i] - arr[i - 1];
max = Math.max(gap, max);
}
max = Math.max(end - arr[n-1], max);
return max;
}
}
That’s different problem with much simpler solution.
Please someone write the text of the original problem