Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts (Leetcode 1465)

Problem Link: https://leetcode.com/problems/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:
        
        maxLength=0
        maxBreadth=0
        horizontalCuts.insert(0,0)
        horizontalCuts.append(h)
        horizontalCuts.sort()
        verticalCuts.insert(0,0)
        verticalCuts.append(w)
        verticalCuts.sort()
        for i in range(1,len(horizontalCuts)):
            maxLength=max(maxLength,horizontalCuts[i]-horizontalCuts[i-1])
        for i in range(1,len(verticalCuts)):
            maxBreadth=max(maxBreadth,verticalCuts[i]-verticalCuts[i-1])
        return (maxLength*maxBreadth)%1000000007
        

Last updated