C# Iterative solution O(n)
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\npublic class Solution {\n    public IList<IList<int>> ReconstructMatrix(int upper
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\npublic class Solution {\n    public IList<IList<int>> ReconstructMatrix(int upper, int lower, int[] colsum)\n    {\n        var result = new List<IList<int>>()\n        {\n            Enumerable.Repeat(0, colsum.Length).ToList(),\n            Enumerable.Repeat(0, colsum.Length).ToList()\n        };\n\n        for (int col = 0; col < colsum.Length; col++)\n        {\n            if (colsum[col] == 0)\n            {\n                continue;\n            }\n\n            if (colsum[col] == 2)\n            {\n                upper--;\n                lower--;\n                result[0][col] = 1;\n                result[1][col] = 1;\n                continue;\n            }\n\n            if (lower == 0 || upper > lower)\n            {\n                upper--;\n                result[0][col] = 1;\n            }\n            else\n            {\n                lower--;\n                result[1][col] = 1;\n            }\n        }\n\n        if (upper != 0 || lower != 0)\n        {\n            return new List<IList<int>>();\n        }\n\n        return result;\n    }\n}\n```
['C#']