Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts LeetCode solution in JavaScript

1
var maxArea = function (h, w, horizontalCuts, verticalCuts) {
2
horizontalCuts.sort((a, b) => a - b);
3
verticalCuts.sort((a, b) => a - b);
4
let max_hor_dis = Math.max(
5
horizontalCuts[0],
6
h - horizontalCuts[horizontalCuts.length - 1]
7
);
8
let max_ver_dis = Math.max(
9
verticalCuts[0],
10
w - verticalCuts[verticalCuts.length - 1]
11
);
12
for (let i = 1; i < horizontalCuts.length; i++) {
13
max_hor_dis = Math.max(
14
max_hor_dis,
15
horizontalCuts[i] - horizontalCuts[i - 1]
16
);
17
}
18
for (let i = 1; i < verticalCuts.length; i++) {
19
max_ver_dis = Math.max(max_ver_dis, verticalCuts[i] - verticalCuts[i - 1]);
20
}
21
return (BigInt(max_hor_dis) * BigInt(max_ver_dis)) % BigInt(1e9 + 7);
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0