Simple and clear python3 solutions | 524 ms - faster than 94.4% solutions
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n) (only for answer)\n Add your space complexity here, 
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$ (only for answer)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python3 []\nclass Solution:\n    def reconstructMatrix(self, upper: int, lower: int, colsum: List[int]) -> List[List[int]]:\n        n = len(colsum)\n        if upper > n or lower > n:\n            return []\n\n        deuces = sum(1 for elem in colsum if elem == 2)\n        if upper < deuces or lower < deuces:\n            return []\n\n        if upper + lower != sum(colsum):\n            return []\n        \n        result = [[0] * n for _ in range(2)]\n        upper -= deuces\n        lower -= deuces\n\n        for i, s in enumerate(colsum):\n            if s == 2:\n                result[0][i] = 1\n                result[1][i] = 1\n            elif s == 1:\n                if upper:\n                    result[0][i] = 1\n                    upper -= 1\n                else:\n                    result[1][i] = 1\n                    lower -= 1\n\n        return result\n```
['Math', 'Greedy', 'Python3']