C++ | BEATS 95 % | explained with comments
\n# Code\n\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int u, int l, vector<int>& c) {\n\n        vector<vector<int>> ans;\n// sum all
\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int u, int l, vector<int>& c) {\n\n        vector<vector<int>> ans;\n// sum all elements in colsum vector and count no of 2\'s present in colsum;\n// if sum is not equal to lower + upper or if no of 2\'s is greater than lower than return empty vector.\n        int cs=0; int cnt2=0;\n        for(int i=0; i<c.size(); i++){\n           cs+=c[i]; \n           if(c[i]==2) cnt2++;\n        }       \n        if(cs != u+l || l<cnt2) return ans;\n//create two vector for upper and lower row. Initialize them with zero;\n        int n=c.size();\n        vector<int> v1(n,0);\n        vector<int> v2(n,0);\n//if column sum for any matrix cell is 2, we will assign them 1. Since for column sum =2, we need 1 in both upper and lower row for that column\n        for(int i=0; i<n; i++){\n            if(c[i]==2){\n                v1[i]=1;\n                u--; c[i]--;\n            }\n        }     \n//For upper row, if upper sum>0 and colsum> 0, assign it with 1; Repeat same for lower vector too\n         for(int i=0; i<n; i++){\n            if(u && c[i] && !v1[i]){\n                v1[i]=1;\n                u--; c[i]--;\n            }\n        }\n        for(int i=0; i<n; i++){\n            if(l && c[i]){\n                v2[i]=1;\n                l--; c[i]--;\n            }\n        }\n        ans.push_back(v1);\n        ans.push_back(v2);\n     return ans;\n    }\n};\n```
['C++']