2943. Maximize Area of Square Hole in Grid Medium

@problem@discussion
#Array#Sorting



1/**
2 * [2943] Maximize Area of Square Hole in Grid
3 *
4 * You are given the two integers, n and m and two integer arrays, hBars and vBars. The grid has n + 2 horizontal and m + 2 vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from 1.
5 * You can remove some of the bars in hBars from horizontal bars and some of the bars in vBars from vertical bars. Note that other bars are fixed and cannot be removed.
6 * Return an integer denoting the maximum area of a square-shaped hole in the grid, after removing some bars (possibly none).
7 *  
8 * <strong class="example">Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2023/11/05/screenshot-from-2023-11-05-22-40-25.png" style="width: 411px; height: 220px;" />
10 * <div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
11 * Input: <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">n = 2, m = 1, hBars = [2,3], vBars = [2]</span>
12 * Output: <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">4</span>
13 * Explanation:
14 * The left image shows the initial grid formed by the bars. The horizontal bars are [1,2,3,4], and the vertical bars are [1,2,3].
15 * One way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.
16 * </div>
17 * <strong class="example">Example 2:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2023/11/04/screenshot-from-2023-11-04-17-01-02.png" style="width: 368px; height: 145px;" />
19 * <div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
20 * Input: <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">n = 1, m = 1, hBars = [2], vBars = [2]</span>
21 * Output: <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">4</span>
22 * Explanation:
23 * To get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.
24 * </div>
25 * <strong class="example">Example 3:
26 * <img alt="" src="https://assets.leetcode.com/uploads/2024/03/12/unsaved-image-2.png" style="width: 648px; height: 218px;" />
27 * <div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
28 * Input: <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">n = 2, m = 3, hBars = [2,3], vBars = [2,4]</span>
29 * Output: <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">4</span>
30 * Explanation:
31 * <span style="color: var(--text-secondary); font-size: 0.875rem;">One way to get the maximum square-shaped hole is by removing horizontal bar 3, and vertical bar 4.</span>
32 * </div>
33 *  
34 * Constraints:
35 * 
36 * 	1 <= n <= 10^9
37 * 	1 <= m <= 10^9
38 * 	1 <= hBars.length <= 100
39 * 	2 <= hBars[i] <= n + 1
40 * 	1 <= vBars.length <= 100
41 * 	2 <= vBars[i] <= m + 1
42 * 	All values in hBars are distinct.
43 * 	All values in vBars are distinct.
44 * 
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/maximize-area-of-square-hole-in-grid/
49// discuss: https://leetcode.com/problems/maximize-area-of-square-hole-in-grid/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54    pub fn maximize_square_hole_area(n: i32, m: i32, h_bars: Vec<i32>, v_bars: Vec<i32>) -> i32 {
55        0
56    }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_2943() {
67    }
68}
69


Back
© 2025 bowen.ge All Rights Reserved.