function maxPoints(points){
if(points.length <2) return points.length;
let maxCount = 0;
for(let i =0;i<points.length;i++){
const slopes = new Map();
let samePointCount = 1;
for(let j =i+1;j<points.length;j++){
if(points[i][0]===points[j][0] &&points[i][1]===points[j][1]){
samePointCount++
continue
}
const dy = points[j][1] - points[i][1];
const dx = points[j][0] - points[i][0];
const gcd = getGCD(dy,dx);
const slope = `${dy/gcd}/${dx/gcd}`
slopes.set(slope,(slopes.get(slope) ||0)+1);
}
let currentMax= 0;
for(let count of slopes.values()){
currentMax = Math.max(currentMax,count)
}
maxCount = Math.max(maxCount,currentMax+samePointCount)
}
return maxCount
}
function getGCD(a,b) {
if(b===0) return a;
return getGCD(b,a%b)
}
const points = [[1,1],[2,2],[3,3],[3,2],[4,1],[5,1]]
console.log(maxPoints(points))
console