FastPrepMax Points on a Line
Problems/Max Points on a Line

Max Points on a Line

Microsoft logoMicrosoft● HardFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Senior Applied Scientist onsite report asks for the maximum number of points on a line from a 2D point array and mentions floating-point precision trouble. The report omits coordinate bounds, duplicate handling and small-input rules. This practice uses exact integer geometry; the judged core matches the report at about 85%.

Given an array of two-dimensional integer points, return the maximum number of input points that lie on one straight line. Repeated coordinates are separate input points and each copy counts.

Use exact integer geometry. Do not compare floating-point slopes: nearby rational slopes may round to the same value, and vertical lines have no finite slope.

Function

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

Examples

Example 1

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

All three distinct points are on the same diagonal line.

Example 2

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

Four points lie on the descending line through [1,4] and [4,1].

Example 3

points = [[0,0],[0,0],[1,1],[2,2],[1,0]]return = 4

Both copies of [0,0] count on the line through [1,1] and [2,2].

Constraints

  • 1 <= points.length <= 300.
  • Each row contains exactly two integer coordinates [x, y].
  • -1000000 <= x, y <= 1000000.
  • Repeated coordinates are allowed; each occurrence counts separately.

More Microsoft problems

  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int maxPointsOnLine(int[][] points) {
        // Write your code here.
    }
}
Checking account…