1
var largestSubmatrix = function (matrix) {3
let m = matrix[0].length;4
let col = new Array(m).fill(0);6
for (let i = 0; i < n; i++) {7
for (let j = 0; j < m; j++) {8
if (matrix[i][j]) col[j]++;11
res = counting(col, res);16
//if you did 84. Largest Rectangle in Histogram, you can replace the following part with your 84 answer and don't forget to sort.17
let counting = function (column, max) {18
let sorted = [...column].sort((a, b) => b - a);20
for (let i = 0; i < sorted.length; i++) {21
if (sorted[i] === sorted[i - 1]) continue;23
while (sorted[j] && sorted[j] >= sorted[i]) j++;24
while (sorted[k] && sorted[k] >= sorted[i]) k--;25
max = Math.max(sorted[i] * Math.abs(k - j + 1), max);