FastPrepMax Points on a Line
Problem · Array

Max Points on a Line

Learn this problem
HardLinkedIn logoLinkedInFULLTIMEONSITE INTERVIEW

Problem statement

Given an array of distinct points where points[i] = [x, y], return the maximum number of points that lie on one straight line.

Function

maxPointsOnLine(points: int[][]) → int

Examples

Example 1

points = [[1,1],[2,2],[3,3]]return = 3

All three points lie on the same diagonal line.

Example 2

points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]return = 4

Four points share the line through [1,4] and [4,1].

Constraints

  • 1 <= points.length <= 300
  • Every point contains exactly two signed 32-bit coordinates.
  • All points are distinct.

More LinkedIn problems

drafts saved locally
public int maxPointsOnLine(int[][] points) {
    // Write your code here.
}
points[[1,1],[2,2],[3,3]]
expected3
checking account