Count the Maximum Number of Collinear Points
Company: LinkedIn
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Find the most points on one line using exact coordinate relationships, including repeated points and vertical or horizontal lines.
Read the full LinkedIn Software Engineer interview experience this question came from
Constraints
- 0 <= len(points) <= 300
- Each point is an integer pair [x, y] with -1000000 <= x, y <= 1000000
- Repeated coordinates are distinct input points and each counts toward the result
- Horizontal and vertical lines are allowed
- Return 0 for no points and 1 for a single point
- Collinearity is exact; do not use a floating-point tolerance
Examples
Input: ([],)
Expected Output: 0
Explanation: No points returns 0.
Input: ([[5, -7]],)
Expected Output: 1
Explanation: A single point returns 1.
Hints
- Every line that contains at least two input points is determined by any two of them. Try fixing one point and grouping the others by how they relate to it.
- Two directions from the same point describe the same line only when they are exactly proportional. Choose a representation in which proportional directions compare equal without using floating-point division.
- A point with the same coordinates as the fixed point lies on every line through it, so count such points separately from the direction groups.