C solution | O(n)
Approach\n Describe your approach to solving the problem. \nIf current colsum[i] is 0 or 2 assign both rows accordingly (both 0 or 1).\n\nIf colsum[i] is 1 assi
# Approach\n<!-- Describe your approach to solving the problem. -->\nIf current `colsum[i]` is `0` or `2` assign both rows accordingly (both `0` or `1`).\n\nIf `colsum[i]` is `1` assign `1` to the row which have higher left over row sum.\n\nDecrement row sums after each value accordingly to the assigned value.\n\nIf final values of `upper` or `lower` are not zero, then it is impossible.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n) for result\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nint** reconstructMatrix(int upper, int lower, int* colsum, int colsumSize, int* returnSize, int** returnColumnSizes) {\n    int **res = malloc(2 * sizeof(int *));\n    *returnSize = 2;\n\n    *returnColumnSizes = malloc(2 * sizeof(int));\n    (*returnColumnSizes)[0] = (*returnColumnSizes)[1] = colsumSize;\n\n    res[0] = malloc(colsumSize * sizeof(int));\n    res[1] = malloc(colsumSize * sizeof(int));\n\n    for(int i = 0; i < colsumSize; i++) {\n        if(colsum[i] == 1) {\n            res[0][i] = (upper >= lower);\n            res[1][i] = 1 - res[0][i];\n        } else {\n            res[0][i] = res[1][i] = (bool)colsum[i];\n        }\n        upper -= res[0][i];\n        lower -= res[1][i];\n    }\n    if(upper || lower) {\n        *returnSize = 0;\n        return NULL;\n    }\n    return res;\n}\n```
['C']