2975. Maximum Square Area by Removing Fences From a Field Medium
1/**
2 * [2975] Maximum Square Area by Removing Fences From a Field
3 *
4 * There is a large (m - 1) x (n - 1) rectangular field with corners at (1, 1) and (m, n) containing some horizontal and vertical fences given in arrays hFences and vFences respectively.
5 * Horizontal fences are from the coordinates (hFences[i], 1) to (hFences[i], n) and vertical fences are from the coordinates (1, vFences[i]) to (m, vFences[i]).
6 * Return the maximum area of a square field that can be formed by removing some fences (possibly none) or -1 if it is impossible to make a square field.
7 * Since the answer may be large, return it modulo 10^9 + 7.
8 * Note: The field is surrounded by two horizontal fences from the coordinates (1, 1) to (1, n) and (m, 1) to (m, n) and two vertical fences from the coordinates (1, 1) to (m, 1) and (1, n) to (m, n). These fences cannot be removed.
9 *
10 * <strong class="example">Example 1:
11 * <img alt="" src="https://assets.leetcode.com/uploads/2023/11/05/screenshot-from-2023-11-05-22-40-25.png" />
12 *
13 * Input: m = 4, n = 3, hFences = [2,3], vFences = [2]
14 * Output: 4
15 * Explanation: Removing the horizontal fence at 2 and the vertical fence at 2 will give a square field of area 4.
16 *
17 * <strong class="example">Example 2:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2023/11/22/maxsquareareaexample1.png" style="width: 285px; height: 242px;" />
19 *
20 * Input: m = 6, n = 7, hFences = [2], vFences = [4]
21 * Output: -1
22 * Explanation: It can be proved that there is no way to create a square field by removing fences.
23 *
24 *
25 * Constraints:
26 *
27 * 3 <= m, n <= 10^9
28 * <font face="monospace">1 <= hF</font>ences<font face="monospace">.length, vFences.length <= 600</font>
29 * <font face="monospace">1 < hFences[i] < m</font>
30 * <font face="monospace">1 < vFences[i] < n</font>
31 * <font face="monospace">hFences</font><font face="monospace"> and </font><font face="monospace">vFences</font><font face="monospace"> are unique.</font>
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/maximum-square-area-by-removing-fences-from-a-field/
37// discuss: https://leetcode.com/problems/maximum-square-area-by-removing-fences-from-a-field/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn maximize_square_area(m: i32, n: i32, h_fences: Vec<i32>, v_fences: Vec<i32>) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_2975() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.