Given R(rows), C(coloumns), N cordinates (x,y) where x<=R && y<=C, we need to find the line which contains maximum mutually equidistant points. Ultimate target is to find the count of those points on that line.
By mutually equidistant, it means all the points on that line should be at equal distance from its neighbouring point. Example: (1,1),(3,3),(5,5),(7,7),(9,9).
We need not consider lines which contains non-mutually equidistant points. Example: (1,1),(2,2),(4,4).
I tried solving it using near N^3 approach but it could not pass all the test cases.
My approach:
For every pair of two points i and j:
Consider another point k:
if(slope(i,j) == slope(i,k))
They are at same line, map these points with the calculated slope.
Set ans = 0.
Then for every slope in the map,
sort all the mapped points and
check whether they are
mutually equidistant.
If they are mutually equidistant,
and their count is greater than ans,
Set ans=count.
Output = ans
Is there a better approach?