09 · Math & Number Theory

#149 Max Points on a Line

Hardsolve on LeetCode ↗

frequently reported atLinkedInAppleGoogleAmazonMicrosoft

the problem

In plain words

You get up to 300 distinct points with integer coordinates. Return the largest number of them that lie on one straight line.

in points = [[1,1],[2,2],[3,3]]

out 3

in points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]

out 4

(1,4), (2,3), (3,2) and (4,1) lie on x + y = 5.

  • 1 ≤ points.length ≤ 300
  • −10⁴ ≤ xᵢ, yᵢ ≤ 10⁴
  • All points are distinct

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #49
      Group Anagrams
      Mediumin Arrays & Strings
    2. #1
      Two Sum
      Easyin Hashing