<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/25/plane1.jpg" style="width: 300px; height: 294px;" />
<pre>
<strong>Input:</strong> points = [[1,1],[2,2],[3,3]]
<strong>Output:</strong> 3
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/25/plane2.jpg" style="width: 300px; height: 294px;" />
<pre>
<strong>Input:</strong> points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
<strong>Output:</strong> 4
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= points.length &lt;= 300</code></li>
	<li><code>points[i].length == 2</code></li>
	<li><code>-10<sup>4</sup> &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 10<sup>4</sup></code></li>
	<li>All the <code>points</code> are <strong>unique</strong>.</li>
</ul>

class Solution {
private:
    double getM(vector<int> a, vector<int> b){
        if(a[0] == b[0])
            return a[0];
        return (a[1] - b[1])/((a[0] - b[0])/1.0);
    }
    double getC(vector<int> a, vector<int> b, double m){
        if(a[0] == b[0])
            return INT_MAX;
        return a[1] - m * a[0];
    }
public:
    int maxPoints(vector<vector<int>>& points) {
        int n = points.size();
        if(n < 2)
            return n;
        map<pair<double, double>, set<vector<int>>> mp;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                double m = getM(points[i], points[j]);
                double c = getC(points[i], points[j], m);
                if(mp.find({m, c}) != mp.end()){
                    mp[{m, c}].insert(points[i]);
                    mp[{m, c}].insert(points[j]);
                }
                else{
                    set<vector<int>> st;
                    st.insert(points[i]);
                    st.insert(points[j]);
                    mp[{m, c}] = st;
                }
            }
        }
        int ans = 0;
        for(auto it : mp){
            ans = max(ans, (int)(it.second).size());
        }
        return ans;
    }
};
88403