Python3 Greedy Solution Counting of 0,1,2 and fill columns as we go leverage invariants
Intuition and Approach\nSee problem title\n\n# Complexity\nM, N := dims(grid)\n\n- Time complexity:\nO(MN)\n\n- Space complexity:\nO(MN) ( E ) O(1) ( I )\n\n# C
# Intuition and Approach\nSee problem title\n\n# Complexity\n$$M, N := dims(grid)$$\n\n- Time complexity:\n$$O(MN)$$\n\n- Space complexity:\n$$O(MN) ( E ) O(1) ( I )$$\n\n# Code\n```python3 []\n\'\'\'\nURL := https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix/description/\n1253. Reconstruct a 2-Row Binary Matrix\n\'\'\'\nclass Solution:\n    def reconstructMatrix(self, upper: int, lower: int, colsum: List[int]) -> List[List[int]]:\n        upperIdx = 0\n        lowerIdx = 1\n        upperPrime = upper\n        lowerPrime = lower\n        oneColCount = 0\n        n = len(colsum)\n        targetMatrix = [[0 for idx in range(n)] for j in range(2)]\n        for ptr, colVal in enumerate(colsum):\n            if(colVal == 2):\n                targetMatrix[upperIdx][ptr] = 1\n                targetMatrix[lowerIdx][ptr] = 1\n                upperPrime -= 1\n                lowerPrime -= 1\n            elif(colVal == 1):\n                oneColCount += 1\n        if(upperPrime + lowerPrime != oneColCount or upperPrime < 0 or lowerPrime < 0):\n            emptyMatrix = []\n            return emptyMatrix\n        for ptr,colVal in enumerate(colsum):\n            if(colVal == 1):\n                if(upperPrime > 0):\n                    targetMatrix[upperIdx][ptr] = 1\n                    upperPrime -= 1\n                elif(upperPrime == 0 and lowerPrime > 0):\n                    targetMatrix[lowerIdx][ptr] = 1\n                    lowerPrime -= 1\n        return targetMatrix\n\n        \n```
['Array', 'Greedy', 'Matrix', 'Python3']