LC 149
LeetCode 149 · Hard

Max Points on a Line

Find the maximum number of points lying on a single straight line.


Try it

Step through the core mechanic. The simulator below runs the computational geometry shape this problem is built on.

Walk the pattern

No dedicated step-through for this one yet. The shape is Computational geometry — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.

The approach

For each anchor point, hash the reduced slope (Δy, Δx) by GCD to every other point; the largest bucket plus the anchor is the best line through it. Take the max over anchors.

AspectValue
PatternComputational geometry
Recognise it byMost collinear points.
Time complexityO(n²)
Space complexityO(n)
DifficultyHard

Who asks it

Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.