Skip to content

Commit d4f50c4

Browse files
authored
Update 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.js
1 parent be711b9 commit d4f50c4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,27 @@ function getMax(limit, cuts) {
1818
}
1919
return max
2020
}
21+
22+
// another
23+
24+
/**
25+
* @param {number} h
26+
* @param {number} w
27+
* @param {number[]} horizontalCuts
28+
* @param {number[]} verticalCuts
29+
* @return {number}
30+
*/
31+
const maxArea = function(h, w, horizontalCuts, verticalCuts) {
32+
return (BigInt(maxGap(h, horizontalCuts)) * BigInt(maxGap(w, verticalCuts))) % BigInt(1e9 + 7)
33+
function maxGap(limit, arr) {
34+
let res = 0
35+
arr.sort((a, b) => a - b)
36+
for(let i = 0, n = arr.length; i < n; i++) {
37+
let tmp = i === 0 ? arr[0] : arr[i] - arr[i - 1]
38+
res = Math.max(res, tmp)
39+
}
40+
res = Math.max(res, limit - arr[arr.length - 1])
41+
42+
return res
43+
}
44+
};

0 commit comments

Comments
 (0)