Talentd
FleetCode

149. Max Points on a Line

Hard31.6% acceptance16 companies

Given an array of points where points[i] = [xi, yi] represents a point on the X-Y 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

Example 2:

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

Constraints:

  • 1 <= points.length <= 300
  • points[i].length == 2
  • -104 <= xi, yi <= 104
  • All the points are unique.
8:14
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def maxPoints(self, points: List[List[int]]) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
[[1,1],[2,2],[3,3]]
Input
[[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
Your code is saved on this device.Solution