[JavaScript] Simple Array
Complexity\n- Time complexity: O(nn)\n- Space complexity: O(nn)\n\n# Code\n\nvar maxTrailingZeros = function(grid) {\n    const n = grid.length, m = grid[0].len
# Complexity\n- Time complexity: $$O(n*n)$$\n- Space complexity: $$O(n*n)$$\n\n# Code\n```\nvar maxTrailingZeros = function(grid) {\n    const n = grid.length, m = grid[0].length;\n    const rowWise = Array.from({ length: n }, () => Array(m)),\n      columnWise = Array.from({ length: n }, () => Array(m));\n\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < m; j++) {\n            grid[i][j] = [getFactorsCount(grid[i][j], 2), getFactorsCount(grid[i][j], 5)];\n            rowWise[i][j] = [(j > 0 ? rowWise[i][j - 1][0] : 0) + grid[i][j][0],\n                (j > 0 ? rowWise[i][j - 1][1] : 0) + grid[i][j][1]];\n            columnWise[i][j] = [(i > 0 ? columnWise[i - 1][j][0] : 0) + grid[i][j][0],\n                (i > 0 ? columnWise[i - 1][j][1] : 0) + grid[i][j][1]];\n        }\n    }\n    \n    function getFactorsCount(value, factor) {\n        let count = 0;\n        while(value % factor == 0) count++, value /= factor;\n        return count;\n    }\n\n    let maxTrailingZeros = 0;\n\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < m; j++) {\n            const top = columnWise[i - 1]?.[j] ?? [0, 0];\n            const left = rowWise[i][j - 1] ?? [0, 0];\n            const right = [rowWise[i].at(-1)[0] - rowWise[i][j][0],\n                rowWise[i].at(-1)[1] - rowWise[i][j][1]];\n            const bottom = [columnWise.at(-1)[j][0] - columnWise[i][j][0],\n                columnWise.at(-1)[j][1] - columnWise[i][j][1]];\n\n            const allDirections = [top, left, right, bottom];            \n            for (let k = 0; k < 4; k++) {\n                for (let l = 0; l < 4; l++) {\n                    if (k == l) continue;\n                    maxTrailingZeros = Math.max(maxTrailingZeros, \n                        Math.min(allDirections[k][0] + allDirections[l][0] + grid[i][j][0], \n                            allDirections[k][1] + allDirections[l][1] + grid[i][j][1]));\n                }\n            }\n        }\n    }\n\n    return maxTrailingZeros;\n};\n```
['Array', 'Prefix Sum', 'JavaScript']