Max Points on a Line

Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.

Example 1
Inputpoints = [[1,1],[2,2],[3,3]]
Output3
The three points all lie on the same straight line.
Example 2
Inputpoints = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
Output4
The maximum number of points on a single straight line is 4.

Constraints

  • 1 <= points.length <= 300
  • points[i].length == 2
  • -10^4 <= xi, yi <= 10^4
  • All the points are unique.

Asked at 16 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate