Python | Simple Solution | O(mn)
Code\n\nclass Solution:\n    def maxTrailingZeros(self, grid: List[List[int]]) -> int:\n        def factors(num):\n            res = [0,0]\n            while nu
# Code\n```\nclass Solution:\n    def maxTrailingZeros(self, grid: List[List[int]]) -> int:\n        def factors(num):\n            res = [0,0]\n            while num > 1 and num%2 == 0:\n                num //= 2\n                res[0] += 1\n            while num > 1 and num%5 == 0:\n                num //= 5\n                res[1] += 1\n            return res\n        def zeros(a, b, c):\n            return min(a[0]+b[0]-c[0], a[1]+b[1]-c[1])\n        m, n = len(grid), len(grid[0])\n        UD = [[0 for i in range(n)] for _ in range(m)]\n        LR = [[0 for i in range(n)] for _ in range(m)]\n        for i in range(m):\n            for j in range(n):\n                UD[i][j] = factors(grid[i][j])\n                LR[i][j] = factors(grid[i][j])\n                UD[i][j][0] += UD[i-1][j][0] if i else 0\n                UD[i][j][1] += UD[i-1][j][1] if i else 0\n                LR[i][j][0] += LR[i][j-1][0] if j else 0\n                LR[i][j][1] += LR[i][j-1][1] if j else 0\n        DU = [[0 for i in range(n)] for _ in range(m)]\n        RL = [[0 for i in range(n)] for _ in range(m)]\n        for i in range(m-1,-1,-1):\n            for j in range(n-1,-1,-1):\n                DU[i][j] = factors(grid[i][j])\n                RL[i][j] = factors(grid[i][j])\n                DU[i][j][0] += DU[i+1][j][0] if i < m - 1 else 0\n                DU[i][j][1] += DU[i+1][j][1] if i < m - 1 else 0\n                RL[i][j][0] += RL[i][j+1][0] if j < n - 1 else 0\n                RL[i][j][1] += RL[i][j+1][1] if j < n - 1 else 0\n        res = 0\n        for i in range(m):\n            for j in range(n):\n                f = factors(grid[i][j])\n                cur = max(zeros(UD[i][j],LR[i][j],f), zeros(UD[i][j],RL[i][j],f), zeros(DU[i][j],LR[i][j],f), zeros(DU[i][j],RL[i][j],f))\n                res = max(res, cur)\n        return res\n                \n        \n```
['Python3']