<p>You are given an array of points in the <strong>X-Y</strong> plane <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>.</p>

<p>Return <em>the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes</em>. If there is not any such rectangle, return <code>0</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/08/03/rec1.JPG" style="width: 500px; height: 447px;" />
<pre>
<strong>Input:</strong> points = [[1,1],[1,3],[3,1],[3,3],[2,2]]
<strong>Output:</strong> 4
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/08/03/rec2.JPG" style="width: 500px; height: 477px;" />
<pre>
<strong>Input:</strong> points = [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]
<strong>Output:</strong> 2
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= points.length &lt;= 500</code></li>
	<li><code>points[i].length == 2</code></li>
	<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 4 * 10<sup>4</sup></code></li>
	<li>All the given points are <strong>unique</strong>.</li>
</ul>


class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        pass


























class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        seen = set()
        res = float('inf')
        for x, y in points:
            for xx, yy in seen:
                if (x, yy) in seen and (xx, y) in seen:
                    area = abs(x-xx) * abs(y-yy)
                    if area < res:
                        res = area 
            seen.add((x, y))
        return res if res != float('inf') else 0

























class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        min_area = float('inf')
        points_set = set(tuple(point) for point in points)

        for i in range(len(points)):
            x, y = points[i]
            for j in range(i+1, len(points)):
                xx, yy = points[j]

                if (xx, y) in points_set and (x, yy) in points_set:
                    area = abs(x - xx) * abs(y - yy)
                    if area == 0:
                        continue
                    min_area = min(min_area, area)
        return min_area if min_area != float('inf') else 0




























class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        points_set = set()
        for p in points:
            points_set.add(tuple(p))

        min_area = float('inf')
        for i in range(len(points)):
            for j in range(i+1, len(points)):
                x1, y1 = points[i]
                x2, y2 = points[j]
                if x1 != x2 and y1 != y2:
                    if (x1, y2) in points_set and (x2, y1) in points_set:
                        area = abs(x2-x1) * abs(y2-y1)
                        min_area = min(min_area, area)
        return min_area if min_area != float('inf') else 0


























class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        points_set = set(tuple(point) for point in points)
        min_area = float('inf')
        for i in range(len(points)):
            for j in range(i):
                x1, y1 = points[i]
                x3, y3 = points[j]

                if (x1, y3) in points_set and (x3, y1) in points_set:
                    area = abs(y3-y1) * abs(x3-x1)
                    if area != 0:
                        min_area = min(min_area, area)
        return min_area if min_area != float('inf') else 0



class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        seen = set()
        min_area = float('inf')
        for i in range(len(points)):
            x1, y1 = points[i]

            for x3, y3 in seen:
                if (x1, y3) in seen and (x3, y1) in seen:
                    area = abs(y3-y1) * abs(x3-x1)
                    if area:
                        min_area = min(min_area, area)
            seen.add((x1, y1))
        return min_area if min_area != float('inf') else 0
                    


























class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        points_set = set([tuple(p) for p in points])

        min_area = float('inf')
        for i in range(len(points)):
            for j in range(i+1, len(points)):
                x1, y1 = points[i]
                x3, y3 = points[j]
                if x1 != x3 and y1 != y3:
                    if (x1, y3) in points_set and (x3, y1) in points_set:
                        area = abs(x3-x1) * abs(y3-y1)
                        min_area = min(min_area, area)
        return min_area if min_area != float('inf') else 0
























class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        seen = set()
        min_area = float('inf')
        for x1, y1 in points:
            for x3, y3 in seen:
                if x1 == x3 or y1 == y3:
                    continue
                if (x1,y3) in seen and (x3,y1) in seen:
                    area = abs(x1-x3) * abs(y1-y3)
                    min_area = min(min_area, area)
            seen.add((x1, y1))
        return min_area if min_area < float('inf') else 0


class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        min_area = float('inf')
        #seen = set([(y, x) for y, x in points])
        seen = set()
        print(seen)
        for i in range(len(points)):
            y1, x1 = points[i]
            for j in range(i+1, len(points)):
                y3, x3 = points[j]
                if y1 == y3 or x3 == x1:
                    continue
                if (y1, x3) in seen and (y3, x1) in seen:
                    area = abs(y3-y1) * abs(x3-x1)
                    min_area = min(min_area, area)
                seen.add((y3, x3))
            seen.add((y1, x1))
        return min_area if min_area < float('inf') else 0




















class Solution:
    def minAreaRect(self, points: List[List[int]]) -> int:
        seen = set(tuple(point) for point in points)
        min_area = float('inf')
        for i in range(len(points)):
            for j in range(i+1, len(points)):
                x1, y1 = points[i]
                x3, y3 = points[j]
                if x1 == x3 or y1 == y3:
                    continue
                if (x1, y3) in seen and (x3, y1) in seen:
                    area = abs(x1-x3) * abs(y1-y3)
                    min_area = min(min_area, area)
        return min_area if min_area < float('inf') else 0
17400