Paths Subjects Questions Quizzes Pricing Search
Advanced Open Pro

Maximum Collinear Points

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

Example 1

Input: points = [[1, 1], [2, 2], [3, 3]]
Output: 3
Explanation: All three points lie on the line y = x.

Example 2

Input: points = [[1, 1], [3, 2], [5, 3], [4, 1], [2, 3], [1, 4]]
Output: 4
Explanation: The best line passes through [1, 1], [3, 2], [5, 3],
and one more point — 4 of the 6 points are collinear.

Constraints

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

Share this question

← Back to Math and Geometry practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.