Max Points on a Line
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an array points where points[i] = [xi, yi] is the location of the i-th point on a 2D plane. A point may appear more than once in the array (two entries can share the exact same coordinates).
Return the maximum number of points that all lie on a single straight line.
A line is defined by any two distinct positions, and a point "lies on" that line if it falls exactly on it. Note that duplicated points stacked on the same coordinate always count together, since any line through that coordinate passes through all of them.
The challenge is to count collinear points without ever computing a floating-point slope, which can introduce rounding errors. Instead, represent each line direction exactly using integer arithmetic.
Examples
Constraints
- `1 <= points.length <= 300`
- `points[i].length == 2`
- `-10^4 <= xi, yi <= 10^4`
- All points are given as integer coordinates.
- The input may contain duplicate points (same coordinate listed multiple times).
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.