Max Points on a Line
Problem statement
Given an array of two-dimensional integer points, return the maximum number of input points that lie on one straight line. Repeated coordinates are separate input points and each copy counts.
Use exact integer geometry. Do not compare floating-point slopes: nearby rational slopes may round to the same value, and vertical lines have no finite slope.
Function
maxPointsOnLine(points: int[][]) → intExamples
Example 1
points = [[1,1],[2,2],[3,3]]return = 3All three distinct points are on the same diagonal line.
Example 2
points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]return = 4Four points lie on the descending line through [1,4] and [4,1].
Example 3
points = [[0,0],[0,0],[1,1],[2,2],[1,0]]return = 4Both copies of [0,0] count on the line through [1,1] and [2,2].
Constraints
1 <= points.length <= 300.- Each row contains exactly two integer coordinates
[x, y]. -1000000 <= x, y <= 1000000.- Repeated coordinates are allowed; each occurrence counts separately.