Skip to content

Max Points on a Line

Given an array of points where points[i] = [xi, yi], return the maximum number of points that lie on the same straight line.

You need to solve this problem efficiently.

InputOutputExplanation
Example 1Result 1Explanation for example 1
Example 2Result 2Explanation for example 2
  • Constraint 1 for Max Points on a Line
  • Constraint 2
  • Constraint 3
ApproachTimeSpaceBest When
Slope CountingO(n)O(1)When applicable
GcdO(n)O(1)When applicable
Brute ForceO(n)O(1)When applicable
★ Recommended

This approach provides an efficient solution for max points on a line.

⏱ Time O(n) Single pass 💾 Space O(1) Minimal storage
max_points_on_a_line_slope_counting.py
# Python Solution
# Problem: max-points-on-a-line
# Approach: slope_counting
# Implementation placeholder for max_points_on_a_line_slope_counting
# This file is auto-generated and should contain the solution code.
def max_points_on_a_line_slope_counting():
pass
if __name__ == "__main__":
pass
🎯 Interview Favourite

This approach provides an efficient solution for max points on a line.

⏱ Time O(n) Single pass 💾 Space O(1) Minimal storage
max_points_on_a_line_gcd.py
# Python Solution
# Problem: max-points-on-a-line
# Approach: gcd
# Implementation placeholder for max_points_on_a_line_gcd
# This file is auto-generated and should contain the solution code.
def max_points_on_a_line_gcd():
pass
if __name__ == "__main__":
pass
✓ Simple

This approach provides an efficient solution for max points on a line.

⏱ Time O(n) Single pass 💾 Space O(1) Minimal storage
max_points_on_a_line_brute_force.py
# Python Solution
# Problem: max-points-on-a-line
# Approach: brute_force
# Implementation placeholder for max_points_on_a_line_brute_force
# This file is auto-generated and should contain the solution code.
def max_points_on_a_line_brute_force():
pass
if __name__ == "__main__":
pass