Given a rectangular cake with height h and width 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, 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 huge number, return this modulo 10^9 + 7.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
classSolution { public: intmaxArea(int h, int w, vector<int>& horizontalCuts, vector<int>& verticalCuts){ sort(horizontalCuts.begin(), horizontalCuts.end()); sort(verticalCuts.begin(), verticalCuts.end()); int width = verticalCuts[0], height = horizontalCuts[0], mod = 1e9 + 7; for(int i = 1; i < horizontalCuts.size(); i++) height = max(height, horizontalCuts[i] - horizontalCuts[i - 1]);
height = max(height, h - horizontalCuts.back());
for(int i = 1; i < verticalCuts.size(); i++) width = max(width, verticalCuts[i] - verticalCuts[i - 1]);