JS solution - simulation
Code\n\n/**\n * @param {number} upper\n * @param {number} lower\n * @param {number[]} colsum\n * @return {number[][]}\n */\nvar reconstructMatrix = function(upp
# 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 matrix = Array.from({length: 2}, ()=> Array(colsum.length).fill(0))\n\n    // PHASE 1: if colsum[i] === 2, obviously it use 1 digit from upper and lower\n    for(let i = 0; i < colsum.length; i++){\n        if(colsum[i] === 2){\n            matrix[0][i] = 1\n            matrix[1][i] = 1\n            upper--\n            lower--\n        }\n    }\n\n    // PHASE 2: when colsum[i] === 1, use digit from max(upper, lower) -> think greedy\n    for(let i = 0; i < colsum.length; i++){\n        if(colsum[i] === 1){\n            if(upper > lower){\n                matrix[0][i] = 1\n                upper--\n            } else {\n                matrix[1][i] = 1\n                lower--\n            }\n        }\n    }\n\n\n    // PHASE 3: check if upper and lower are all used \n    if(upper !== 0 || lower !== 0) return []\n\n    return matrix\n};\n```
['JavaScript']