Python3 O(mn) Vertical/horizontal Prefix Sum Solution
First step is convert each number to how many 2s and 5s it contains, these are the ingredients of 10. \nThen is just standard counting using prefix array in bot
First step is convert each number to how many 2s and 5s it contains, these are the ingredients of 10. \nThen is just standard counting using prefix array in both vertical and horizontal way. \n```\nclass Solution:\n    def maxTrailingZeros(self, grid: List[List[int]]) -> int:\n      m, n = len(grid), len(grid[0])\n      new_grid = [[[0, 0] for _ in range(n)] for _ in range(m)]\n      for i in range(m):\n        for j in range(n):\n          target = grid[i][j]\n          count2, count5 = 0, 0\n          while target % 2 == 0:\n            count2 += 1\n            target = target//2\n          while target % 5 == 0:\n            count5 += 1\n            target = target//5\n          new_grid[i][j] = [count2, count5]\n      verti_grid = [[[0, 0] for _ in range(n)] for _ in range(m)]\n      hori_grid = [[[0, 0] for _ in range(n)] for _ in range(m)]\n      \n      for i in range(m):\n        sum2, sum5 = 0, 0\n        for j in range(n):\n          sum2 += new_grid[i][j][0]\n          sum5 += new_grid[i][j][1]\n          hori_grid[i][j] = [sum2, sum5]\n          \n      for j in range(n):\n        sum2, sum5 = 0, 0\n        for i in range(m):\n          sum2 += new_grid[i][j][0]\n          sum5 += new_grid[i][j][1]\n          verti_grid[i][j] = [sum2, sum5]\n        \n      res = -sys.maxsize\n      \n      for i in range(m):\n        for j in range(n):\n          start2, start5 = hori_grid[i][j][0], hori_grid[i][j][1]\n          start2_up, start5_up = start2 + verti_grid[i][j][0] - new_grid[i][j][0], \\\n                                 start5 + verti_grid[i][j][1] - new_grid[i][j][1]\n          start2_down, start5_down = start2 + verti_grid[-1][j][0] - verti_grid[i][j][0], \\\n                                     start5 + verti_grid[-1][j][1] - verti_grid[i][j][1]\n          res = max([min(start2_up, start5_up), min(start2_down, start5_down), res])\n\n      for i in range(m):\n        for j in range(n):\n          if j != 0:\n            start2, start5 = hori_grid[i][-1][0] - hori_grid[i][j-1][0], \\\n                             hori_grid[i][-1][1] - hori_grid[i][j-1][1]\n          else:\n            start2, start5 = hori_grid[i][-1][0], hori_grid[i][-1][1]\n          start2_up, start5_up = start2 + verti_grid[i][j][0] - new_grid[i][j][0], \\\n                                 start5 + verti_grid[i][j][1] - new_grid[i][j][1]\n          start2_down, start5_down = start2 + verti_grid[-1][j][0] - verti_grid[i][j][0], \\\n                                     start5 + verti_grid[-1][j][1] - verti_grid[i][j][1]\n          res = max([min(start2_up, start5_up), min(start2_down, start5_down), res])\n          \n      return res\n```
['Prefix Sum', 'Python3']