1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts Medium

@problem@discussion
#Array#Greedy#Sorting



1/**
2 * [1465] Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
3 *
4 * You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where:
5 * 
6 * 	horizontalCuts[i] is the distance from the top of the rectangular cake to the i^th horizontal cut and similarly, and
7 * 	verticalCuts[j] is the distance from the left of the rectangular cake to the j^th vertical cut.
8 * 
9 * 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 large number, return this modulo 10^9 + 7.
10 *  
11 * Example 1:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2020/05/14/leetcode_max_area_2.png" style="width: 225px; height: 240px;" />
13 * Input: h = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3]
14 * Output: 4 
15 * Explanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green piece of cake has the maximum area.
16 * 
17 * Example 2:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2020/05/14/leetcode_max_area_3.png" style="width: 225px; height: 240px;" />
19 * Input: h = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1]
20 * Output: 6
21 * Explanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green and yellow pieces of cake have the maximum area.
22 * 
23 * Example 3:
24 * 
25 * Input: h = 5, w = 4, horizontalCuts = [3], verticalCuts = [3]
26 * Output: 9
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	2 <= h, w <= 10^9
32 * 	1 <= horizontalCuts.length <= min(h - 1, 10^5)
33 * 	1 <= verticalCuts.length <= min(w - 1, 10^5)
34 * 	1 <= horizontalCuts[i] < h
35 * 	1 <= verticalCuts[i] < w
36 * 	All the elements in horizontalCuts are distinct.
37 * 	All the elements in verticalCuts are distinct.
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/
43// discuss: https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn max_area(h: i32, w: i32, horizontal_cuts: Vec<i32>, vertical_cuts: Vec<i32>) -> i32 {
49        0
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_1465() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.