C++ O(n*m) Solution || Prefix Sum Solution
cpp\ntypedef pair<int,int> pii;\ntypedef vector<pair<int,int>> vpii;\ntypedef vector<vpii> vvpii;\nclass Solution {\npublic:\n    pii get_count(int x,int p=0){\
```cpp\ntypedef pair<int,int> pii;\ntypedef vector<pair<int,int>> vpii;\ntypedef vector<vpii> vvpii;\nclass Solution {\npublic:\n    pii get_count(int x,int p=0){\n        int c_2=0,c_5=0;\n        while(x%2==0)\n            x/=2,c_2+=1;\n        while(x%5==0)\n            x/=5,c_5+=1;\n        if(p==1)\n            return {-c_2,-c_5};\n        return {c_2,c_5};\n    }\n    void print(vvpii &arr){\n        for(int i=0;i<arr.size();i++){\n            for(int j=0;j<arr[0].size();j++){\n                cout<<"{"<<arr[i][j].first<<","<<arr[i][j].second<<"}, ";\n            }\n            cout<<endl;\n        }\n        cout<<\'\\n\';\n    }\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int n=grid.size();\n        int m=grid[0].size();\n        vvpii horizontal(n,vpii(m)),vertical(n,vpii(m));\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                auto [a,b]=get_count(grid[i][j]);\n                if(j==0){\n                    horizontal[i][j]={a,b};\n                    continue;\n                }\n                horizontal[i][j]=horizontal[i][j-1];\n                horizontal[i][j].first+=a;\n                horizontal[i][j].second+=b;\n            }\n        }\n        // print(horizontal);\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                auto [a,b]=get_count(grid[i][j]);\n                if(i==0){\n                    vertical[i][j]={a,b};\n                    continue;\n                }\n                vertical[i][j]=vertical[i-1][j];\n                vertical[i][j].first+=a;\n                vertical[i][j].second+=b;\n            }\n        }\n        // print(vertical);\n        int ans=0;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                pii h=horizontal[i][j];\n                pii v=vertical[i][j];\n                pii c=get_count(grid[i][j]);\n//                 case1:  _|\n                int a1=h.first+v.first-c.first;\n                int b1=h.second+v.second-c.second;\n//                 case 2: |_\n                int a2=v.first+(horizontal[i][m-1].first-horizontal[i][j].first);\n                int b2=v.second+(horizontal[i][m-1].second-horizontal[i][j].second);\n//                 case 3: --\\\n                int a3=h.first+vertical[n-1][j].first-vertical[i][j].first;\n                int b3=h.second+vertical[n-1][j].second-vertical[i][j].second;\n//                 case 4: /--\n                int a4=(vertical[n-1][j].first-vertical[i][j].first)+(horizontal[i][m-1].first-horizontal[i][j].first)+c.first;\n                int b4=(vertical[n-1][j].second-vertical[i][j].second)+(horizontal[i][m-1].second-horizontal[i][j].second)+c.second;       \n                \n                ans=max({ans,min(a1,b1),min(a2,b2),min(a3,b3),min(a4,b4)});\n            }\n        }\n        return ans;\n    }\n};\n```
['Prefix Sum']