Skip to content

Commit 5b9b274

Browse files
authored
Create 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.js
1 parent 0e3ccb1 commit 5b9b274

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {number} h
3+
* @param {number} w
4+
* @param {number[]} horizontalCuts
5+
* @param {number[]} verticalCuts
6+
* @return {number}
7+
*/
8+
const maxArea = function(h, w, horizontalCuts, verticalCuts) {
9+
return getMax(h, horizontalCuts) * getMax(w, verticalCuts) % (10 ** 9 + 7)
10+
};
11+
12+
function getMax(limit, cuts) {
13+
cuts.sort((a, b) => a - b)
14+
const n = cuts.length
15+
let max = Math.max(cuts[0], limit - cuts[n - 1])
16+
for(let i = 1; i < n; i++) {
17+
max = Math.max(max, cuts[i] - cuts[i - 1])
18+
}
19+
return max
20+
}

0 commit comments

Comments
 (0)