java.lang.Object
g1401_1500.s1465_maximum_area_of_a_piece_of_cake_after_horizontal_and_vertical_cuts.Solution

public class Solution extends Object
1465 - Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts.<p>Medium</p> <p>You are given a rectangular cake of size <code>h x w</code> and two arrays of integers <code>horizontalCuts</code> and <code>verticalCuts</code> where:</p> <ul> <li><code>horizontalCuts[i]</code> is the distance from the top of the rectangular cake to the <code>i<sup>th</sup></code> horizontal cut and similarly, and</li> <li><code>verticalCuts[j]</code> is the distance from the left of the rectangular cake to the <code>j<sup>th</sup></code> vertical cut.</li> </ul> <p>Return <em>the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays</em> <code>horizontalCuts</code> <em>and</em> <code>verticalCuts</code>. Since the answer can be a large number, return this <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/05/14/leetcode_max_area_2.png" alt="" /></p> <p><strong>Input:</strong> h = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green piece of cake has the maximum area.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/05/14/leetcode_max_area_3.png" alt="" /></p> <p><strong>Input:</strong> h = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1]</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green and yellow pieces of cake have the maximum area.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> h = 5, w = 4, horizontalCuts = [3], verticalCuts = [3]</p> <p><strong>Output:</strong> 9</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= h, w <= 10<sup>9</sup></code></li> <li><code>1 <= horizontalCuts.length <= min(h - 1, 10<sup>5</sup>)</code></li> <li><code>1 <= verticalCuts.length <= min(w - 1, 10<sup>5</sup>)</code></li> <li><code>1 <= horizontalCuts[i] < h</code></li> <li><code>1 <= verticalCuts[i] < w</code></li> <li>All the elements in <code>horizontalCuts</code> are distinct.</li> <li>All the elements in <code>verticalCuts</code> are distinct.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxArea

      public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts)