Greedy Solution - Beats 98% :-D
Intuition\nJust a greedy solution which try to reconstruct the matry in a logical way, step by step.\n\n# Approach\n1. checks that the sum of upper and lower is
# Intuition\nJust a greedy solution which try to reconstruct the matry in a logical way, step by step.\n\n# Approach\n1. checks that the sum of `upper` and `lower` is equal to the sum of all the elements in `colsum`. This is a necessary condition to construct the solution. If this condition is not respected: we return `[]`.\n2. if `colssum[idx] == 2`, then there is a one in the `upper` row and one in the `lower` row. So we get rid of this cases.\n3. we distribuite the ones that are still in `colssum`.\n4. Finally, if we distribuited too much ones and `upper`, or `lower`, is negative, we should return `[]`.\n\n# Complexity\n- Time complexity: $$O(len(colsum))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(len(colsum))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def reconstructMatrix(\n        self, upper: int, lower: int, colsum: List[int]\n    ) -> List[List[int]]:\n        # step 1\n        if upper + lower != sum(colsum):\n            return []\n\n        n = len(colsum)\n        solution = [[0 for j in range(n)] for _ in range(2)]\n\n        # step 2\n        for idx in range(len(colsum)):\n            if colsum[idx] == 2:\n                solution[0][idx],  solution[1][idx] = 1, 1\n                colsum[idx] = 0\n                upper -= 1\n                lower -= 1\n\n        # step 3\n        for idx in range(len(colsum)):\n            if colsum[idx] == 1:\n                if upper > lower and solution[0][idx] == 0:\n                    upper -= 1\n                    solution[0][idx] += 1\n                    colsum[idx] -= 1\n                elif lower >= upper and solution[1][idx] == 0:\n                    lower -= 1\n                    solution[1][idx] += 1\n                    colsum[idx] -= 1\n                else:\n                    return []\n\n        # step 4\n        if upper < 0 or lower < 0:\n            return []\n            \n        return solution\n\n```
['Python3']