Skip to content

Commit 7a57eed

Browse files
committed
Add solution #1465
1 parent a8e36d8 commit 7a57eed

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,315 LeetCode solutions in JavaScript
1+
# 1,316 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1120,6 +1120,7 @@
11201120
1462|[Course Schedule IV](./solutions/1462-course-schedule-iv.js)|Medium|
11211121
1463|[Cherry Pickup II](./solutions/1463-cherry-pickup-ii.js)|Hard|
11221122
1464|[Maximum Product of Two Elements in an Array](./solutions/1464-maximum-product-of-two-elements-in-an-array.js)|Easy|
1123+
1465|[Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts](./solutions/1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.js)|Medium|
11231124
1466|[Reorder Routes to Make All Paths Lead to the City Zero](./solutions/1466-reorder-routes-to-make-all-paths-lead-to-the-city-zero.js)|Medium|
11241125
1470|[Shuffle the Array](./solutions/1470-shuffle-the-array.js)|Easy|
11251126
1472|[Design Browser History](./solutions/1472-design-browser-history.js)|Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* 1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
3+
* https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/
4+
* Difficulty: Medium
5+
*
6+
* You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and
7+
* verticalCuts where:
8+
* - horizontalCuts[i] is the distance from the top of the rectangular cake to the ith horizontal
9+
* cut and similarly, and
10+
* - verticalCuts[j] is the distance from the left of the rectangular cake to the jth vertical cut.
11+
*
12+
* Return the maximum area of a piece of cake after you cut at each horizontal and vertical position
13+
* provided in the arrays horizontalCuts and verticalCuts. Since the answer can be a large number,
14+
* return this modulo 109 + 7.
15+
*/
16+
17+
/**
18+
* @param {number} h
19+
* @param {number} w
20+
* @param {number[]} horizontalCuts
21+
* @param {number[]} verticalCuts
22+
* @return {number}
23+
*/
24+
var maxArea = function(h, w, horizontalCuts, verticalCuts) {
25+
horizontalCuts.sort((a, b) => a - b);
26+
verticalCuts.sort((a, b) => a - b);
27+
28+
let maxHeight = Math.max(horizontalCuts[0], h - horizontalCuts[horizontalCuts.length - 1]);
29+
let maxWidth = Math.max(verticalCuts[0], w - verticalCuts[verticalCuts.length - 1]);
30+
31+
for (let i = 1; i < horizontalCuts.length; i++) {
32+
maxHeight = Math.max(maxHeight, horizontalCuts[i] - horizontalCuts[i - 1]);
33+
}
34+
for (let i = 1; i < verticalCuts.length; i++) {
35+
maxWidth = Math.max(maxWidth, verticalCuts[i] - verticalCuts[i - 1]);
36+
}
37+
38+
return Number((BigInt(maxHeight) * BigInt(maxWidth)) % BigInt(1000000007));
39+
};

0 commit comments

Comments
 (0)