[C++] One Pass Solution , O(N) Time & O(1) Space
\nclass Solution\n{\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int> &colsum)\n    {\n        int n = 2, m = colsum.size();
```\nclass Solution\n{\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int> &colsum)\n    {\n        int n = 2, m = colsum.size();\n        vector<vector<int>> A(n, vector<int>(m, 0));\n        for (int i = 0; i < m; i++)\n        {\n            if (colsum[i] == 2)\n            {\n                A[0][i] = 1;\n                A[1][i] = 1;\n                upper--;\n                lower--;\n            }\n            else if (colsum[i] == 0)\n            {\n                A[0][i] = 0;\n                A[1][i] = 0;\n            }\n            else\n            {\n                if (upper >= lower)\n                {\n                    A[0][i] = 1;\n                    A[1][i] = 0;\n                    upper--;\n                }\n                else\n                {\n                    A[0][i] = 0;\n                    A[1][i] = 1;\n                    lower--;\n                }\n            }\n        }\n        if (lower != 0 || upper != 0)\n        {\n            A.clear();\n        }\n        return A;\n    }\n};\n```
[]