JavaScript  | Simple Greedy Solution | O(N)
Approach\nThe solution implements a greedy approach to reconstruct two rows, row1 and row2, based on a given column sum array (colsum), upper and lower constrai
# Approach\nThe solution implements a greedy approach to reconstruct two rows, row1 and row2, based on a given column sum array (colsum), upper and lower constraints. The algorithm iterates through each column, making decisions on how to distribute ones in both rows to match the column sums efficiently. It uses conditions to handle cases where colsum is 0, skips unnecessary iterations, and adjusts the distribution based on the values of upper and lower. The code ensures the total sum of the reconstructed rows aligns with the given upper and lower constraints, returning a valid reconstruction or an empty array if not possible.\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\n/**\n * @param {number} upper\n * @param {number} lower\n * @param {number[]} colsum\n * @return {number[][]}\n */\nvar reconstructMatrix = function(upper, lower, colsum) {\n    const length = colsum.length; \n    const row1 = new Array(length).fill(0);\n    const row2 = new Array(length).fill(0);\n    let totalSum = colsum.reduce((acc, currValue)=> acc + currValue, 0);\n\n    if(totalSum!==upper+lower) return [];\n    \n    for(let i = 0 ; i<colsum.length; i++){\n        if(upper <0 || lower<0) return [];\n        if(colsum[i]===0) continue;\n        if(colsum[i]===2) {\n            row1[i] = 1;\n            upper--;\n            row2[i] = 1;\n            lower--;\n        } \n        else if(upper>lower) {\n            upper--;\n            row1[i]++;\n        }\n        else {\n            lower--;\n            row2[i]++;\n        }\n    }\n    return [row1, row2];\n};\n```
['Greedy', 'JavaScript']