Clean Python Implementation - Numpy Trick
Implementation solution by @votrubac here in Python:\nhttps://leetcode.com/problems/maximum-trailing-zeros-in-a-cornered-path/discuss/1955515/Prefix-Sum-of-Fact
Implementation solution by @votrubac here in Python:\nhttps://leetcode.com/problems/maximum-trailing-zeros-in-a-cornered-path/discuss/1955515/Prefix-Sum-of-Factors-2-and-5\n\n\nUsing numpy makes the vector additions much Cleaner for Python! \n\n```\nimport numpy as np\nclass Solution:\n    def maxTrailingZeros(self, grid: List[List[int]]) -> int:\n        def factors(i, f):\n            return 0 if i % f != 0 else 1 + factors(i // f, f)\n\n        R = len(grid)\n        C = len(grid[0])\n        res = 0\n\n        # Prefix sums for horizontal. Pad for last column\n        hor = [[np.array([0, 0])] * (C + 1) for _ in range(R)]\n\n        # Prefix sums for vertical. Pad for last row\n        vert = [[np.array([0, 0])] * (C) for _ in range(R + 1)]\n\n        for i in range(R):\n            for j in range(C):\n                f25 = np.array(\n                    [factors(grid[i][j], 2), factors(grid[i][j], 5)]\n                )\n                vert[i + 1][j] = vert[i][j] + f25\n                hor[i][j + 1] = hor[i][j] + f25\n\n        for i in range(R):\n            for j in range(C):\n                \n\t\t\t\t# notice overlap vetween v1 and v2 at i, j\n\t\t\t\tv1 = vert[i + 1][j]\n                v2 = vert[R][j] - vert[i][j]\n\t\t\t\t\n\t\t\t\t# notice gap vetween h1 and h2 at i, j\n                h1 = hor[i][j]\n                h2 = hor[i][C] - hor[i][j + 1]\n\n                res = max(\n                    res,\n                    min(v1 + h1),\n                    min(v1 + h2),\n                    min(v2 + h1),\n                    min(v2 + h2),\n                )\n\n        return res\n```
['Python', 'Python3']