3382. Maximum Area Rectangle With Point Constraints II Hard
1/**
2 * [3382] Maximum Area Rectangle With Point Constraints II
3 *
4 * There are n points on an infinite plane. You are given two integer arrays xCoord and yCoord where (xCoord[i], yCoord[i]) represents the coordinates of the i^th point.
5 * Your task is to find the maximum area of a rectangle that:
6 *
7 * Can be formed using four of these points as its corners.
8 * Does not contain any other point inside or on its border.
9 * Has its edges parallel to the axes.
10 *
11 * Return the maximum area that you can obtain or -1 if no such rectangle is possible.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">xCoord = [1,1,3,3], yCoord = [1,3,1,3]</span>
16 * Output: <span class="example-io">4</span>
17 * Explanation:
18 * <strong class="example"><img alt="Example 1 diagram" src="https://assets.leetcode.com/uploads/2024/11/02/example1.png" style="width: 229px; height: 228px;" />
19 * We can make a rectangle with these 4 points as corners and there is no other point that lies inside or on the border. Hence, the maximum possible area would be 4.
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">xCoord = [1,1,3,3,2], yCoord = [1,3,1,3,2]</span>
24 * Output: <span class="example-io">-1</span>
25 * Explanation:
26 * <strong class="example"><img alt="Example 2 diagram" src="https://assets.leetcode.com/uploads/2024/11/02/example2.png" style="width: 229px; height: 228px;" />
27 * There is only one rectangle possible is with points [1,1], [1,3], [3,1] and [3,3] but [2,2] will always lie inside it. Hence, returning -1.
28 * </div>
29 * <strong class="example">Example 3:
30 * <div class="example-block">
31 * Input: <span class="example-io">xCoord = [1,1,3,3,1,3], yCoord = [1,3,1,3,2,2]</span>
32 * Output: <span class="example-io">2</span>
33 * Explanation:
34 * <strong class="example"><img alt="Example 3 diagram" src="https://assets.leetcode.com/uploads/2024/11/02/example3.png" style="width: 229px; height: 228px;" />
35 * The maximum area rectangle is formed by the points [1,3], [1,2], [3,2], [3,3], which has an area of 2. Additionally, the points [1,1], [1,2], [3,1], [3,2] also form a valid rectangle with the same area.
36 * </div>
37 *
38 * Constraints:
39 *
40 * 1 <= xCoord.length == yCoord.length <= 2 * 10^5
41 * 0 <= xCoord[i], yCoord[i] <= 8 * 10^7
42 * All the given points are unique.
43 *
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/maximum-area-rectangle-with-point-constraints-ii/
48// discuss: https://leetcode.com/problems/maximum-area-rectangle-with-point-constraints-ii/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53 pub fn max_rectangle_area(x_coord: Vec<i32>, y_coord: Vec<i32>) -> i64 {
54
55 }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_3382() {
66 }
67}
68
Back
© 2025 bowen.ge All Rights Reserved.