Skip to content
Decoder

Max Points on a Line

Hard

Problem

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.

Example 1

Input
points = [[0, 0], [2, 2], [5, 5], [1, 3]]
Output
3
Why
the line y = x

Example 2

Input
points = [[0, 0], [1, 2], [2, 4], [3, 0], [0, 3]]
Output
3

Example 3

Input
points = [[7, 7]]
Output
1

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.