
Max Points on a Line (hard)
Problem Statement
Given an array containing points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that are on the same straight line.
Examples
-
Example 1:
- Input: points =
[[1,2], [3,6], [5,10], [7,14]] - Expected Output:
4 - Justification: All points lie on the line (y = 2x), forming a straight line with all given points.
- Input: points =
-
Example 2:
- Input: points =
[[1,1], [2,2], [3,3], [8,10]] - Expected Output:
3 - Justification: The first three points form a line with the equation (y = x), while the fourth point does not lie on this line.
- Input: points =
-
Example 3:
- Input: points =
[[0,0],[-3,0], [1,1], [2,2], [3, 0], [6, 0]] - Expected Output:
4 - Justification: Points ([1,1]), ([2,2]), and ([0,0]) lie on the line (y = x), making a straight line. The point ([0,0]), (-3, 0), (3, 0), and (6, 0) lie on the x-axis. So, the maximum points on the straight line is 4.
- Input: points =
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory