C++ | Very Simple Solution | With Explanation
When colsum[i] is 2, then it is obviously 1 in both rows for ith column.\nWhen colsum[i] is 1, then first set the row based on which sum is bigger i.e. Give pre
When colsum[i] is 2, then it is obviously 1 in both rows for ith column.\nWhen colsum[i] is 1, then first set the row based on which sum is bigger i.e. Give preference to the row sum which is greater and then the row with lower sum. \n\n```\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) \n    {\n        int n = colsum.size();\n        vector<vector<int>> ans(2,vector<int>(n,0));    \n        for(int i=0;i<n;i++)\n        {\n            if(lower<0 or upper<0)\n                return {};\n            if(colsum[i]==2)\n            {\n                ans[0][i] = 1;\n                ans[1][i] = 1;\n                upper--;\n                lower--;\n            }\n            else if(colsum[i]==1)\n            {\n                if(upper>lower)\n                {\n                    ans[0][i]=1;\n                    upper--;\n                } \n                else\n                {\n                    ans[1][i]=1;\n                    lower--;\n                }\n            }\n        }\n        if(lower!=0 or upper!=0)\n            return {};\n        return ans;\n    }\n};\n```
[]