1253. Reconstruct a 2-Row Binary Matrix
ApproachKeep adding 1 to the first row if upper >= lower, otherwise add it to the second row.Complexity

Time complexity: O(n)


Space complexity: O(2∗n)

Code
# Approach
Keep adding 1 to the first row if upper >= lower, otherwise add it to the second row.

# Complexity
- Time complexity: $$O(n)$$

- Space complexity: $$O(2*n)$$

# Code
```python []
class Solution(object):
    def reconstructMatrix(self, upper, lower, colsum):
        """
        :type upper: int
        :type lower: int
        :type colsum: List[int]
        :rtype: List[List[int]]
        """
        n, m = 2, len(colsum)
        matrix = [ [0] * m for _ in range(n) ]
        for index in range(m):
            if colsum[index] == 1:
                # distribute 1 uniformly between arrays
                if upper >= lower and upper > 0:
                    matrix[0][index] = 1
                    upper -= 1
                elif lower > upper and lower > 0:
                    matrix[1][index] = 1
                    lower -= 1
                else:
                    return []
            elif colsum[index] == 2 and upper > 0 and lower > 0:
                matrix[1][index] = matrix[0][index] = 1
                upper -= 1
                lower -= 1
            elif colsum[index] != 0:
                return []
        return [] if upper > 0 or lower > 0 else matrix
```
['Python']