Max Points on a Line

Hard

Topics
ArrayHash TableMathGeometry

You are given grid, where each row is a distinct point [x, y] on the plane. Return the maximum number of points that lie on the same straight line.

Example 1

Input:  grid = [[1,1],[2,2],[3,3]]
Output: 3

Example 2

Input:  grid = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
Output: 4

Constraints

  • 1 <= grid.length <= 300
  • grid[i].length == 2
  • all points are distinct
Run ⌘' · Submit ⌘⏎