215. Maximum Points on a Line

Given an array of unqiue points nums, where each point is represented as nums[i] = [xi, yi] on a 2D plane, find the maximum number of points that lie on the same line.

Example 1:

Input: nums = [[0,0], [1,1], [2,2], [3,3]]

Output: 4

Explanation: All four points lie on the line with slope 1, so the maximum number of points on the same line is 4.

Example 2:

Input: nums = [[0,1], [2,3], [4,5], [1,2], [3,4], [2,2]]

Output: 5

Explanation: The points [0,1], [1,2], [2,3], [3,4], and [4,5] all lie on the same straight line, so the maximum number is 5.

Now Your Turn!

Pick the correct output for the given input

Input: nums = [[2,3], [3,4], [5,1], [7,2], [6,5], [9,4]]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 500
  • nums[i].length == 2
  • -104 <= xi, yi <= 104

Fun Facts

0
class Solution {
public:
int maximumPointsOnALine(vector<vector<int>> & nums) {
}
};
 
Test Case

Input:

Nums