<p>You are given an <code>m x n</code> binary matrix <code>matrix</code>.</p>

<p>You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from <code>0</code> to <code>1</code> or vice versa).</p>

<p>Return <em>the maximum number of rows that have all values equal after some number of flips</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> matrix = [[0,1],[1,1]]
<strong>Output:</strong> 1
<strong>Explanation:</strong> After flipping no values, 1 row has all values equal.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> matrix = [[0,1],[1,0]]
<strong>Output:</strong> 2
<strong>Explanation:</strong> After flipping values in the first column, both rows have equal values.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> matrix = [[0,0,0],[0,0,1],[1,1,0]]
<strong>Output:</strong> 2
<strong>Explanation:</strong> After flipping values in the first two columns, the last two rows have equal values.
</pre>

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

<ul>
	<li><code>m == matrix.length</code></li>
	<li><code>n == matrix[i].length</code></li>
	<li><code>1 &lt;= m, n &lt;= 300</code></li>
	<li><code>matrix[i][j]</code> is either&nbsp;<code>0</code> or <code>1</code>.</li>
</ul>

class Solution {
public:

    // long long pow(long long n){
        
    //     if (n==0){
    //         return 1;
    //     }
    //     long long temp=pow(n/2);
    //     temp=temp*temp;
    //     if (n%2==0){
    //         return temp;
    //     }
    //     else{
    //         return temp*2;
    //     }
    // }
    string flip(string b){
        string a="";
        // cout<<b<<" ";
        for (int i=0;i<b.length();i++){
            if (b[i]=='1'){
                a=a+"0";
            }
            else{
                a=a+"1";
            }
        }
        // cout<<a<<"ji";
        return a;
    }
    int maxEqualRowsAfterFlips(vector<vector<int>>& matrix) {
        unordered_map<string,int> mp;
        for (int i=0;i<matrix.size();i++){
            string s="";
            for (int j=0;j<matrix[0].size();j++){
                if (matrix[i][j]==1){
                    s=s+"1";                 
                }
                else{
                    s=s+"0";
                }
            }
            mp[s]++;
        }

        int ma=0; 
        for (auto it :mp){
            string a=it.first;
            string b=flip(a);
            int g=0;

            if (mp.find(b)!=mp.end()){
                g=mp[b];
            }
            // cout<<a<<" "<<b<<" ";
            ma=max(ma,it.second+g);
        }
        return ma;
        
    }
};
422800