# [1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts](https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/) ###### tags: `Array`, `Amazon OA` Description: You are given a rectangular cake of size` h x w` and two arrays of integers `horizontalCuts` and `verticalCuts` where: * `horizontalCuts[i]` is the distance from the top of the rectangular cake to the ith horizontal cut and similarly, and * `verticalCuts[j]` is the distance from the left of the rectangular cake to the jth vertical cut. Return the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays `horizontalCuts` and `verticalCuts`. Since the answer can be a large number, return this **modulo** `10^9 + 7`. Solution: ```java= class Solution { public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) { Arrays.sort(horizontalCuts); Arrays.sort(verticalCuts); int mod = 1000000000 + 7; int maxH = findMaxDiff(horizontalCuts, h); int maxV = findMaxDiff(verticalCuts, w); return (int)((long)maxH * (long)maxV % mod); } private int findMaxDiff(int[] arr, int limit) { int n = arr.length; int max = Math.max(arr[0], limit - arr[n - 1]); for (int i = 1; i < n; i++) { max = Math.max(max, arr[i] - arr[i - 1]); } return max; } } ```