Search⌘ K
AI Features

Solution: Max Points on a Line

Discover how to solve the problem of finding the largest number of points on a straight line by applying slope calculations between points. Understand how to group collinear points using mathematical and geometric principles, and implement an efficient O(n²) solution. This lesson helps you master a common coding interview pattern involving math and geometry.

Statement

Given an integer array of points where points[i]=[xi,yi]\text{points}[i] = [x_i, y_i] represents a point on the X–Y plane, your task is to return the maximum number of points on the same straight line.

Constraints:

  • 11 \leq points.length 300\leq 300

  • points[i].length =2= 2

  • ...