DP concise explanation 97% faster Javascript JS ES6
\nALGORITHM: \n- Initiate an aux-matrix with zeroes to begin with.\n- The first row of aux-matrix is same as matrix\'s first row.\n- Values in aux-matrix reflec
\n`ALGORITHM:` \n- Initiate an aux-matrix with zeroes to begin with.\n- The first row of aux-matrix is same as matrix\'s first row.\n- Values in aux-matrix reflect the height for that column, like this:\n```\n["1","0","1","0","0"]\n["1","0","1","1","1"]\n["1","1","1","1","1"]\n["1","0","0","1","0"]\nbecomes\n["1","0","1","0","0"]\n["2","0","2","1","1"]\n["3","1","3","2","2"]\n["4","0","0","3","0"]]\n```\n- Another for-loop moves the column-pointer backwards, while updating the maxArea \n\n`CODE:`\n```\nconst maximalRectangle = function(matrix) {\n  if (!matrix.length) return 0;\n  const ROWS = matrix.length;\n  const COLS = matrix[0].length;\n  const dp = Array.from({length:ROWS}, ()=> Array(COLS).fill(0));\n  let maxArea = 0;\n  \n  for (let row = 0; row < ROWS; row++) {\n    for (let col = 0; col < COLS; col++) {\n\t\n\t  //update height\n      if(row === 0) dp[row][col] = matrix[row][col] == \'1\' ? 1 : 0;\n      else dp[row][col] = matrix[row][col] == \'1\' ? (dp[row-1][col] + 1) : 0;\n\t  \n      //update area \n\t  let minHeight = dp[row][col];\n\t  for(let pointer = col; pointer >= 0; pointer--) {\n\t\t if (minHeight === 0) break;\n\t\t if (dp[row][pointer] < minHeight) minHeight = dp[row][pointer];\n\t\t maxArea = Math.max(maxArea, minHeight * (col - pointer + 1));\n\t  }\n   }\n  }\n  return maxArea;  \n};\n```\n![image](https://assets.leetcode.com/users/images/6e93b417-3583-4f58-9804-5719bc8dd99e_1621868328.6235888.png)\n
['Dynamic Programming', 'JavaScript']