<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 {
public:
    float inf = numeric_limits<float>::infinity();
    pair<float, float> getLineParams(vector<int>& p1, vector<int>& p2) {
        if(p1[0] > p2[0])
            return getLineParams(p2, p1);
        float k = p1[0] != p2[0] ? (p1[1] - p2[1]) / float(p1[0] - p2[0]) : inf;

        float n = k != inf ? p1[1] - p1[0] * k : p1[0];
        return {k, n};
    }

    int maxPoints(vector<vector<int>>& points) {
        map<pair<float, float>, set<int>> dp;
        if(points.size() == 1)
            return 1;
        set<int> indices;
        for (int i = 0; i < points.size(); ++i)
            indices.emplace_hint(indices.end(), i);
        int maxSize = 0;
        for(int i=0;i<points.size() - 1;i++) {
            auto& p = points[i];
            set<int> excluded;
            for(int j=i+1;j<points.size();j++) {
                if(excluded.find(j) != excluded.end())
                    continue;
                auto params = getLineParams(points[i], points[j]);
                auto it = dp.find(params);
                if(it != dp.end()) {
                    excluded.insert(it->second.begin(), it->second.end());
                    it->second.insert(i);
                    it->second.insert(j);
                } else {
                    dp[params] = {i, j};
                }
                maxSize = max(maxSize, (int)dp[params].size());
            }
        }
        return maxSize;
    }
};
32421