#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <numeric>
int maximumCollinearPoints(std::vector<std::vector<int>>& points) {
int res = 0;
for (int i = 0; i < points.size(); i++) {
res = std::max(res, maxPointsFromFocalPoint(i, points));
}
return res;
}
int maxPointsFromFocalPoint(int focalPointIndex, std::vector<std::vector<int>>& points) {
std::map<std::pair<int, int>, int> slopesMap;
int maxPoints = 0;
for (int j = 0; j < points.size(); j++) {
if (j != focalPointIndex) {
std::pair<int, int> currSlope = getSlope(points[focalPointIndex], points[j]);
slopesMap[currSlope]++;
maxPoints = std::max(maxPoints, slopesMap[currSlope]);
}
}
return maxPoints + 1;
}
std::pair<int, int> getSlope(std::vector<int>& p1, std::vector<int>& p2) {
int rise = p2[1] - p1[1];
int run = p2[0] - p1[0];
if (run == 0) {
return {1, 0};
}
int gcdVal = std::gcd(rise, run);
return {rise / gcdVal, run / gcdVal};
}