Easy to understand
Intuition and Approach\nGrid only consist of 0 or 1, and row size is 2. Now if column sum is 0 meaning both the rows of that column have value 0, if it is 2, bo
# Intuition and Approach\nGrid only consist of 0 or 1, and row size is 2. Now if column sum is 0 meaning both the rows of that column have value 0, if it is 2, both the columns of that row must have value 1, if it is 1, means either upper or lower row have value 1. If the upper is greater then we supposed to give that 1 to upper row of that column otherwise give to lower and recrease the sum of upper or lower or both according to condition.\n\nIf after performing this, upper and lower are not 0 ,(as it is the sum of rows) then answer cannot be found.Otherwise, return answer array.\n\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$ ($$O(n)$$ considering "ans" array) \n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) {\n        int n = colsum.size();\n        \n        vector<vector<int>>ans(2,vector<int>(n,0));\n\n        for(int i=0;i<n;i++){\n            int col = colsum[i];\n\n            if(col == 2){\n                upper--,lower--;\n                ans[0][i] = ans[1][i] = 1;\n            }else if(col == 1){\n                if(upper>=lower){\n                    upper--;\n                    ans[0][i] = 1;\n                }else{\n                    lower--;\n                    ans[1][i] = 1;\n                }\n            }\n        }\n\n        if(lower!=0 || upper != 0)\n            return {};\n        return ans;\n    }\n};\n```
['C++']