Skip to content

Max Points on a Line

HardBit Manipulation & Math
Decode it first. Clues, constraints, pattern and plan before any code.

You are given points, where points[i] = [x, y] is a point on a flat plane with integer coordinates. No two points are the same. Return the largest number of points that lie on one straight line.

points = [[0, 0], [2, 2], [5, 5], [1, 3]]           →  3   (the line y = x)
points = [[0, 0], [1, 2], [2, 4], [3, 0], [0, 3]]   →  3
points = [[7, 7]]                                   →  1

Constraints

  • 1 <= points.length <= 300
  • -10^4 <= x, y <= 10^4
  • All points are distinct.