Kotlin Solution
\n    fun maxTrailingZeros(grid: Array<IntArray>): Int {\n        val m = grid.size\n        val n = grid[0].size\n        val twosLeftToRight = Array(m) { IntA
```\n    fun maxTrailingZeros(grid: Array<IntArray>): Int {\n        val m = grid.size\n        val n = grid[0].size\n        val twosLeftToRight = Array(m) { IntArray(n) }\n        val fivesLeftToRight = Array(m) { IntArray(n) }\n        val twosUpToDown = Array(m) { IntArray(n) }\n        val fivesUpToDown = Array(m) { IntArray(n) }\n\n        var maxTrailingZeros = 0\n        for (i in grid.indices) {\n            for (j in 0 until n) {\n                var num = grid[i][j]\n                var five = 0\n                while (num % 5 == 0) {\n                    five++\n                    num /= 5\n                }\n                num = grid[i][j]\n                var two = 0\n                while (num % 2 == 0) {\n                    two++\n                    num /= 2\n                }\n                var leftTwo = two\n                var leftFive = five\n                var upTwo = two\n                var upFive = five\n\n                if (j != 0) {\n                    leftTwo += twosLeftToRight[i][j - 1]\n                    leftFive += fivesLeftToRight[i][j - 1]\n                }\n                twosLeftToRight[i][j] = leftTwo\n                fivesLeftToRight[i][j] = leftFive\n                if (i != 0) {\n                    upTwo += twosUpToDown[i - 1][j]\n                    upFive += fivesUpToDown[i - 1][j]\n                }\n                twosUpToDown[i][j] = upTwo\n                fivesUpToDown[i][j] = upFive\n            }\n        }\n\n        for (i in grid.indices) {\n            for (j in 0 until n) {\n                var upBeginning5 = 0\n                var upBeginning2 = 0\n                if (i != 0) {\n                    upBeginning5 = fivesUpToDown[i - 1][0]\n                    upBeginning2 = twosUpToDown[i - 1][0]\n                }\n                var downBeginnings5 = 0\n                var downBeginnings2 = 0\n                if (i != m - 1) {\n                    downBeginnings5 = fivesUpToDown[m - 1][0] - fivesUpToDown[i][0]\n                    downBeginnings2 = twosUpToDown[m - 1][0] - twosUpToDown[i][0]\n                }\n\n                var topEndings5 = 0\n                var topEndings2 = 0\n                if (i != 0) {\n                    topEndings5 = fivesUpToDown[i - 1][n - 1]\n                    topEndings2 = twosUpToDown[i - 1][n - 1]\n                }\n                var downEndings5 = 0\n                var downEndings2 = 0\n                if (i != m - 1) {\n                    downEndings5 = fivesUpToDown[m - 1][n - 1] - fivesUpToDown[i][n - 1]\n                    downEndings2 = twosUpToDown[m - 1][n - 1] - twosUpToDown[i][n - 1]\n                }\n\n                val leftSide5 = fivesLeftToRight[i][j]\n                val leftSide2 = twosLeftToRight[i][j]\n\n                var topSide5 = 0\n                var topSide2 = 0\n                if (i != 0) {\n                    topSide5 = fivesUpToDown[i - 1][j]\n                    topSide2 = twosUpToDown[i - 1][j]\n                }\n\n                val downSide5 = fivesUpToDown[m - 1][j] - fivesUpToDown[i][j]\n                val downSide2 = twosUpToDown[m - 1][j] - twosUpToDown[i][j]\n\n                var rightSide5 = 0\n                var rightSide2 = 0\n                if (j != 0) {\n                    rightSide5 = fivesLeftToRight[i][n - 1] - fivesLeftToRight[i][j - 1]\n                    rightSide2 = twosLeftToRight[i][n - 1] - twosLeftToRight[i][j - 1]\n                }\n\n                var min = Math.min(leftSide2 + topSide2, topSide5 + leftSide5)\n                maxTrailingZeros = Math.max(maxTrailingZeros, min)\n                min = Math.min(rightSide2 + topSide2, topSide5 + rightSide5)\n                maxTrailingZeros = Math.max(maxTrailingZeros, min)\n                min = Math.min(leftSide2 + downSide2, downSide5 + leftSide5)\n                maxTrailingZeros = Math.max(maxTrailingZeros, min)\n                min = Math.min(rightSide2 + downSide2, downSide5 + rightSide5)\n                maxTrailingZeros = Math.max(maxTrailingZeros, min)\n                min = Math.min(leftSide2 + upBeginning2, upBeginning5 + leftSide5)\n                maxTrailingZeros = Math.max(maxTrailingZeros, min)\n                min = Math.min(leftSide2 + downBeginnings2, downBeginnings5 + leftSide5)\n                maxTrailingZeros = Math.max(maxTrailingZeros, min)\n                min = Math.min(rightSide2 + downEndings2, downEndings5 + rightSide5)\n                maxTrailingZeros = Math.max(maxTrailingZeros, min)\n                min = Math.min(rightSide2 + topEndings2, topEndings5 + rightSide5)\n                maxTrailingZeros = Math.max(maxTrailingZeros, min)\n            }\n        }\n        return maxTrailingZeros\n    }\n```
['Prefix Sum', 'Kotlin']