Greedy Javascript || Easy to understand
\n\n# Code\n\nfunction reconstructMatrix(upper: number, lower: number, colsum: number[]): number[][] {\n    let grid = Array(2).fill(0).map(() => Array(colsum.l
\n\n# Code\n```\nfunction reconstructMatrix(upper: number, lower: number, colsum: number[]): number[][] {\n    let grid = Array(2).fill(0).map(() => Array(colsum.length).fill(0));\n    let j = 0, k = 0;\n\n    if(colsum.reduce((a, b) => a + b, 0) != upper + lower) {\n        return []\n    }\n\n    const twos = colsum.filter((item) => item == 2).length;\n\n    if(lower < twos) return [];\n    if(upper < twos) return []\n\n    for(let i = 0; i < colsum.length; i++) {\n        if(colsum[i] == 2 && upper != 0 && lower != 0) {\n            upper -= 1;\n            lower -= 1;\n            grid[0][j] = 1;\n            grid[1][k] = 1;\n        }\n        j++;\n        k++;\n    }\n\n    j = 0;\n    k = 0;\n    \n    for(let i = 0; i < colsum.length; i++) {\n        if(colsum[i] == 1) {\n            if(upper != 0) {\n                grid[0][j] = 1;\n                upper -= 1\n            } else if(lower != 0) {\n                grid[1][k] = 1;\n                lower -= 1;\n            }\n        }\n        j++;\n        k++;\n    }\n\n    \n    console.log(\'last\', lower, upper)\n    return grid;\n    return [[],[]]\n};\n```
['Greedy', 'TypeScript', 'JavaScript']