3380. Maximum Area Rectangle With Point Constraints I Medium
1/**
2 * [3380] Maximum Area Rectangle With Point Constraints I
3 *
4 * You are given an array points where points[i] = [xi, yi] represents the coordinates of a point on an infinite plane.
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">points = [[1,1],[1,3],[3,1],[3,3]]</span>
16 * Output: 4
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<!-- notionvc: f270d0a3-a596-4ed6-9997-2c7416b2b4ee -->. 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">points = [[1,1],[1,3],[3,1],[3,3],[2,2]]</span>
24 * Output: -1
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">points = [[1,1],[1,3],[3,1],[3,3],[1,2],[3,2]]</span>
32 * Output: 2
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 <= points.length <= 10
41 * points[i].length == 2
42 * 0 <= xi, yi <= 100
43 * All the given points are unique.
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/maximum-area-rectangle-with-point-constraints-i/
49// discuss: https://leetcode.com/problems/maximum-area-rectangle-with-point-constraints-i/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn max_rectangle_area(points: Vec<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_3380() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.