Easy | Backtracking Solution
\n\t class Solution {\n\t\t public:\n\t\t\tvoid sol( vector>& arr ,unordered_set&vis , int row ,  int count , int &ans){\n\t\t\t\tif(row == arr.size()){\n\t\t\t
\n\t class Solution {\n\t\t public:\n\t\t\tvoid sol( vector<vector<int>>& arr ,unordered_set<int>&vis , int row ,  int count , int &ans){\n\t\t\t\tif(row == arr.size()){\n\t\t\t\t\tans = max(count ,ans );\n\t\t\t\t\treturn ; \n            \n        }\n        \n        for(int i =  0;i<arr[0].size();i++){\n            if(vis.count(i)){\n                continue ;\n            }else {\n                \n                vis.insert(i);\n                sol(arr,vis , row+1,count + arr[row][i],ans );\n                vis.erase(i);\n            }\n        }\n        \n    }\n    \n    int maxCompatibilitySum(vector<vector<int>>& s, vector<vector<int>>& m) {\n        vector<vector<int>>arr(s.size(),vector<int>(m.size())) ;\n        for(int i = 0;i<s.size();i++){\n            \n            for(int j = 0;j<m.size();j++){\n               int val = 0 ;\n                \n                for(int k = 0 ;k<s[0].size();k++ ){\n                   if(m[i][k] == s[j][k]){\n                       val++;\n                   } \n                }\n                arr[i][j] = val ;\n            }\n        }\n        // for checking visited column\n        unordered_set<int>vis ; \n        \n        int ans = 0 ;\n        sol(arr,vis,0,0,ans);\n        return ans ;\n        \n    }};\n
[]