Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Jibbscript/df4aed5f224d3acaee8aa78197bb2740 to your computer and use it in GitHub Desktop.

Select an option

Save Jibbscript/df4aed5f224d3acaee8aa78197bb2740 to your computer and use it in GitHub Desktop.
Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
class Solution:
def maxArea(self, h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int:
start, end = 0, 0
max_h, max_w = 0, 0
horizontalCuts.sort()
verticalCuts.sort()
for i in range(len(horizontalCuts)):
end = horizontalCuts[i]
curr = end - start
if curr > max_h:
max_h = curr
start = end
curr = h - end
if curr > max_h:
max_h = curr
start, end = 0, 0
for j in range(len(verticalCuts)):
end = verticalCuts[j]
curr = end - start
if curr > max_w:
max_w = curr
start = end
curr = w - end
if curr > max_w:
max_w = curr
max_area = (max_h * max_w)
if max_area > (10 ** 9):
max_area = max_area % ((10 ** 9) + 7)
return max_area
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment