Simple Brute force using prefix sum of number of factors of 2 and 5
\nclass Solution {\npublic:\n    \n    int count(int num,int v){\n        int cnt=0;\n        while(num>0 and num%v==0){\n            cnt++;\n            num/=v
```\nclass Solution {\npublic:\n    \n    int count(int num,int v){\n        int cnt=0;\n        while(num>0 and num%v==0){\n            cnt++;\n            num/=v;\n        }\n        return cnt;\n    }\n    \n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        vector<vector<pair<int,int>>> h,v;\n        int n=grid.size(),m=grid[0].size();\n        h.resize(n,vector<pair<int,int>>(m));\n        v.resize(n,vector<pair<int,int>>(m));\n        for(int i=0;i<n;i++){\n            int two=0,fv=0;\n            for(int j=0;j<m;j++){\n                two+=count(grid[i][j],2);\n                fv+=count(grid[i][j],5);\n                h[i][j]={two,fv};\n            }\n        }\n        for(int j=0;j<m;j++){\n            int two=0,fv=0;\n            for(int i=0;i<n;i++){\n                two+=count(grid[i][j],2);\n                fv+=count(grid[i][j],5);\n                v[i][j]={two,fv};\n            }\n        }\n        int ans=INT_MIN;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                int v12=(v[i][j].first+h[i][j].first)-count(grid[i][j],2);\n                int v15=(v[i][j].second+h[i][j].second)-count(grid[i][j],5);\n                \n                int v21=(v[i][j].first+h[i][m-1].first)-h[i][j].first;\n                int v25=(v[i][j].second+h[i][m-1].second)-h[i][j].second;\n\n                int v31=(h[i][j].first+v[n-1][j].first)-v[i][j].first;\n                int v35=(h[i][j].second+v[n-1][j].second)-v[i][j].second;\n                \n                int v41=(h[i][m-1].first+v[n-1][j].first)-(v[i][j].first+h[i][j].first)+count(grid[i][j],2);\n                int v45=(h[i][m-1].second+v[n-1][j].second)-(v[i][j].second+h[i][j].second)+count(grid[i][j],5);\n                int k=max({min(v12,v15),min(v21,v25),min(v31,v35),min(v41,v45)});\n                ans=max(ans,k);\n            }\n        }\n        return ans;\n    }\n};\n```
[]