Max Points on a Line

Arrays & Hashing, problem 9 of 9

Max Points on a Line

Hard

LC #149

hash maptuple keysmathgeometry

Not attempted yet

You're given a list of distinct points on a plane, each [x, y] with integer coordinates. Return the largest number of points that lie on one straight line.

Example 1

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

Example 2

Input: points = [[1, 2], [2, 4], [0, 5],
                 [3, 6], [4, 1], [5, 10]]
Output: 4
[1,2], [2,4], [3,6], [5,10] are on y = 2x.

Example 3

Input: points = [[0, 0]]
Output: 1

Constraints

  • 1 ≤ len(points) ≤ 300
  • -10^9 ≤ x, y ≤ 10^9
  • All points are distinct

Python

Loading draft…

Test results

9 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 6 hidden

Run examples, then submit all tests.