20ms || Greedy || Explanation || Beginner friendly
Intuition\nThe most important thing to notice in the problem is that if the sum of the current column is zero, both cells have to be zero and if the sum is two 
# Intuition\nThe most important thing to notice in the problem is that if the sum of the current column is zero, both cells have to be zero and if the sum is two - both cells will be equal to one.\n\n# Approach\nThe greedy approach consists of two iterations of the \'colsum\' array. On the first go we fill the cells which value we know (0 or 2), and on the second iteration we fill the columns with values of one depending on how much ones we can place on the upper and the lower row. In the end we check for leftover cells we need to fill and if we have - we return an empty array.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) {\n        ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);\n\n        //The matrix containing the answer\n        vector < vector <int> > ans(2, vector <int> (colsum.size(), 0));\n\n        //First iteration\n        for (int i = 0; i < colsum.size(); i++)\n        {\n            //If the colsum is zero we ignore it\n            if (!colsum[i])\n                continue;\n            \n            //If it is two we fill both cells and we \n            //decrease the values of upper and lower\n            if (colsum[i] == 2)\n            {\n                upper--;\n                lower--;\n                ans[0][i] = 1;\n                ans[1][i] = 1;\n            }\n\n            //If we filled more cells than required\n            //return an empty array\n            if (upper < 0 || lower < 0)\n                return {};\n        }\n\n        //Second iteration\n        for (int i = 0; i < colsum.size(); i++)\n            if (colsum[i] == 1)\n            {\n                //If we can fill the upper cell we fill it\n                if (upper > 0)\n                {\n                    upper--;\n                    ans[0][i] = 1;\n                }\n                //If we can\'t we fill the bottom one\n                else\n                {\n                    lower--;\n                    ans[1][i] = 1;\n                }\n\n                //If we run out of cells to fill \n                //we return an empty arrat\n                if (lower < 0)\n                    return {};\n            }\n\n        //If the lower and upper values are both zero\n        //then and only then we return the matrix\n        if (!lower && !upper)\n            return ans;\n\n        return {};\n    }\n};\n```
['C++']