Count the Maximum Number of Collinear Points

Read the full interview experience this question came from →

Quick Overview

Find the most points on one line using exact coordinate relationships, including repeated points and vertical or horizontal lines.

Count the Maximum Number of Collinear Points

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given points in a two-dimensional plane, return the largest number of input points that lie on one straight line. ### Function Contract Implement `maximum_collinear_points(points) -> int`, where every element of `points` is an integer pair `[x, y]`. ### Constraints and Clarifications The following bounds and repeated-point convention are explicit practice assumptions: - `0 <= len(points) <= 300`. - Coordinates are integers between `-1000000` and `1000000`, inclusive. - Repeated coordinates represent 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 that can merge different slopes. - Aim for `O(n^2)` pair processing, apart from integer-normalization costs. ### Examples ```text points = [[0, 0], [1, 1], [2, 2], [2, 0]] Output: 3 ``` Three points lie on the line `y = x`. ```text points = [[1, 1], [1, 1], [2, 2], [3, 4]] Output: 3 ``` The two occurrences of `(1, 1)` and the point `(2, 2)` lie on one line. ```hint Compare directions from one point Lines through a fixed point can be grouped by direction. Decide how to represent equal directions exactly and how coincident points should affect every possible line through that point. ```

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

|Home/Coding & Algorithms/LinkedIn
LinkedIn logo
LinkedIn
Sep 12, 2026
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Given points in a two-dimensional plane, return the largest number of input points that lie on one straight line.

Function Contract

Implement maximum_collinear_points(points) -> int, where every element of points is an integer pair [x, y].

Constraints and Clarifications

The following bounds and repeated-point convention are explicit practice assumptions:

  • 0 <= len(points) <= 300 .
  • Coordinates are integers between -1000000 and 1000000 , inclusive.
  • Repeated coordinates represent 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 that can merge different slopes.
  • Aim for O(n^2) pair processing, apart from integer-normalization costs.

Examples

points = [[0, 0], [1, 1], [2, 2], [2, 0]]
Output: 3

Three points lie on the line y = x.

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

The two occurrences of (1, 1) and the point (2, 2) lie on one line.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...