Best C++ solution using map


#1

int n = a.size(),res = 0,cur,ver,same;
if(n<=2) return n;
map<pair<int,int>,int> m;
for(int i = 0;i<n;i++){
cur = ver = same = 0;
for(int j = i+1;j<n;j++){
if(a[i] == a[j]&&b[i]==b[j]) same++;
else if(b[i]==b[j]) ver++;
else{
int x = a[j]-a[i],y = b[j]-b[i],g = __gcd(x,y);
y/=g;x/=g;
m[{x,y}]++;
cur = max(cur,m[{x,y}]);
}

    }
    res = max(res,max(cur,ver)+same+1);
    m.clear();
}
return res;

#2

Why have you used “ver” variable ??
Without this the code is self sufficient.