Max Points on a Line
Reported by candidates from LinkedIn's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The LinkedIn OA reported in September 2026 asks for the max points on a line, and the trap is hiding in how you compare slopes. Divide two integers into a float and you'll get collisions that quietly fail hidden tests. You've got an OA coming up, so here's the pattern: fix one point, hash the direction to every other point, take the best count. It's a hash-table problem with a geometry costume on. If you blank on the slope normalization mid-assessment, StealthCoder runs invisibly as a safety net and shows you the approach in real time.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Fix an anchor point i. For every point j after it, compute dx and dy, then reduce both by their gcd. Normalize the sign so dx is positive, and if dx is zero force dy to 1. Use the pair as a hash key, count occurrences, and the best line through i is the max count plus one. Repeat for every anchor. That's O(n^2) with n up to 300, which is fine. The pitfall is floating point. Coordinates are signed 32-bit, so dy/dx as a double can make two different slopes look equal. Vertical lines also divide by zero. Since all points are distinct, you don't need duplicate handling. Return 1 if there's only one point, and the loop handles two points naturally. If the sign normalization slips under pressure, StealthCoder is there as a hedge during the live OA.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Max Points on a Line cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as max points on a line. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass LinkedIn's OA.
LinkedIn reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Max Points on a Line FAQ
What's the trick to Max Points on a Line?+
Anchor on each point, then count how many other points share the same direction from it. Store the direction as a gcd-reduced (dx, dy) pair in a hash map. The best answer is the largest bucket plus one for the anchor. That's O(n^2) and handles vertical lines cleanly.
Why can't I just use dy/dx as the slope?+
Floating point division loses precision with large 32-bit coordinates, so different slopes can compare equal. Vertical lines also divide by zero. Reduce dx and dy by their gcd and key on the integer pair. Normalize signs so equivalent directions match.
How hard is this one really for the LinkedIn OA?+
It's a hard-tagged problem, but the solution is short once you know the hash-of-directions idea. The difficulty is edge cases: vertical lines, negative signs, and precision. With n at most 300, an O(n^2) approach passes comfortably.
Do I need to handle duplicate points?+
No. The problem states all points are distinct, so you skip duplicate logic. A single point returns 1, and two points always form a line, so the answer is at least min(n, 2). The anchor loop covers both naturally.
How do I prepare for this in 48 hours?+
Write the gcd-normalized slope solution from scratch twice. Test on a vertical line, a horizontal line, negative deltas, and the two-point case. Know why you normalize sign. If you can explain that, you can rebuild the rest under pressure.