# Storage Optimization - Company-specific OAs / Amazon OA

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;
}
}``````