Leetcode Problem 1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts

1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts

Leetcode Solutions

Key approach of the solution

  1. Sort the horizontalCuts array in ascending order.
  2. Sort the verticalCuts array in ascending order.
  3. Initialize maxHeight to the maximum of the first horizontal cut and the distance from the last horizontal cut to the bottom edge of the cake.
  4. Iterate through the sorted horizontalCuts to find the maximum distance between two consecutive cuts, updating maxHeight accordingly.
  5. Initialize maxWidth to the maximum of the first vertical cut and the distance from the last vertical cut to the right edge of the cake.
  6. Iterate through the sorted verticalCuts to find the maximum distance between two consecutive cuts, updating maxWidth accordingly.
  7. Calculate the maximum area as maxHeight * maxWidth % (10^9 + 7).
  8. Return the maximum area.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...