Problem · Array
Max Points on a Line
Learn this problemProblem statement
Given an array of distinct points where points[i] = [x, y], return the maximum number of points that lie on one straight line.
Function
maxPointsOnLine(points: int[][]) → intExamples
Example 1
points = [[1,1],[2,2],[3,3]]return = 3All three points lie on the same diagonal line.
Example 2
points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]return = 4Four points share the line through [1,4] and [4,1].
Constraints
1 <= points.length <= 300- Every point contains exactly two signed 32-bit coordinates.
- All points are distinct.