Max Points on a Line
You get points on a plane, no two the same. Find the largest number of them that lie on one straight line. Our example: (1, 1), (2, 3), (4, 2), (3, 5), (0, 4), (5, 9) — the answer is 4: (1, 1), (2, 3), (3, 5) and (5, 9) lie on one line.
- input
points: an array of points on a plane, each[x, y]with integer coordinates; no two points are the same.- returns
- The largest number of the points that lie on one straight line.
- constraints
- 1 ≤ points.length ≤ 300
- −10⁴ ≤ xᵢ, yᵢ ≤ 10⁴
- all the points are different
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {number[][]} points
* @return {number}
*/
function maxPoints(points) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more hash map problems
- 1Two SumEasysolve
- 217Contains DuplicateEasysolve
- 242Valid AnagramEasysolve
- 169Majority ElementEasysolve
- 383Ransom NoteEasysolve
- 205Isomorphic StringsEasysolve
- 290Word PatternEasysolve
- 219Contains Duplicate IIEasysolve
- 49Group AnagramsMediumsolve
- 128Longest Consecutive SequenceMediumsolve
- 36Valid SudokuMediumsolve
- 138Copy List with Random PointerMediumsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.