class Solution {
public:
int minAreaRect(vector<vector<int>>& points) {
set<pair<int, int>> pointSet;
for(auto point : points) {
pointSet.insert({point[0], point[1]});
}
int res = INT_MAX;
for (int i = 0; i < points.size(); i++) {
int x0 = points[i][0];
int y0 = points[i][1];
for (int j = i + 1; j < points.size(); j++) {
int x1 = points[j][0];
int y1 = points[j][1];
pair<int, int> p1 {x0, y1};
pair<int, int> p2 {x1, y0};
if (x0 != x1 && y0 != y1 && pointSet.count(p1) && pointSet.count(p2)) {
res = min(res, abs((x0 - x1) * (y0 - y1)));
}
}
}
return (res == INT_MAX? 0 : res);
}
};