C++ || EASY TO UNDERSTAND || Simple Prefix Sum + Greedy Approach  :)
Approach is very simple but the implementation needed some level of patience.\n\nwe first create a matrix with the number of factors of 2\'s and 5\'s in each of
**Approach is very simple but the implementation needed some level of patience.**\n\n**we first create a matrix with the number of factors of 2\'s and 5\'s in each of the grids of the given matrix. I used vector<vector<pair<int,int>>> v , to do the same.**\n\n**Then, we are creating 4 prefix sum matrices(of the number of 2\'s and 5\'s) which will store the value of the prefixsum from left to right(named as ltr), right to left(rtl), up to down(utd) and down to up(dtu). After creating the matrices we will be iterating through the v and finding the maximum of the minimum of 2\'s and 5\'s on the 4 possible cases (utd+ltr),(utd+rtl),(dtu+ltr),(dtu+rtl) and that maximum will be our answer.**\n\n```\n#define ll long long int\nclass Solution {\npublic:\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int n=grid.size();\n        int m=grid[0].size();\n        vector<vector<pair<ll,ll>>> v(n,vector<pair<ll,ll>>(m,{0,0})),ltr,utd,rtl,dtu;\n        \n        for(ll i=0;i<n;i++)\n        {\n            for(ll j=0;j<m;j++)\n            {\n                ll z=grid[i][j],c1=0,c2=0;\n                while(z%2==0)\n                {\n                    z/=2;\n                    c1++;\n                }\n                while(z%5==0)\n                {\n                    z/=5;\n                    c2++;\n                }\n                v[i][j].first=c1;\n                v[i][j].second=c2;\n            }\n        }\n        ltr=utd=rtl=dtu=v;\n        for(ll i=0;i<n;i++)\n        {\n            for(ll j=1;j<m;j++)\n            {\n                ltr[i][j].first+=ltr[i][j-1].first;\n                ltr[i][j].second+=ltr[i][j-1].second;\n            }\n        }\n        for(ll i=0;i<n;i++)\n        {\n            for(ll j=m-2;j>=0;j--)\n            {\n                rtl[i][j].first+=rtl[i][j+1].first;\n                rtl[i][j].second+=rtl[i][j+1].second;\n            }\n        }\n        for(ll j=0;j<m;j++)\n        {\n            for(ll i=1;i<n;i++)\n            {\n                utd[i][j].first+=utd[i-1][j].first;\n                utd[i][j].second+=utd[i-1][j].second;\n            }\n        }\n        for(ll j=0;j<m;j++)\n        {\n            for(ll i=n-2;i>=0;i--)\n            {\n                dtu[i][j].first+=dtu[i+1][j].first;\n                dtu[i][j].second+=dtu[i+1][j].second;\n            }\n        }\n        ll ans=0;\n        for(ll i=0;i<n;i++)\n        {\n            for(ll j=0;j<m;j++)\n            {\n                ll c1,c2,c3,c4;\n                ll x1,x2,x3,x4;\n                ll a,b;\n                a=v[i][j].first;\n                b=v[i][j].second;       \n                \n                c1=ltr[i][j].first;\n                c2=rtl[i][j].first;\n                \n                c3=utd[i][j].first;\n                c4=dtu[i][j].first;\n                \n                x1=ltr[i][j].second;\n                x2=rtl[i][j].second;\n                \n                x3=utd[i][j].second;\n                x4=dtu[i][j].second;\n                \n                ans=max(ans,min(c3+c1-a,x3+x1-b));\n                ans=max(ans,min(c3+c2-a,x3+x2-b));\n                ans=max(ans,min(c4+c1-a,x4+x1-b));\n                ans=max(ans,min(c4+c2-a,x4+x2-b));\n            }\n        }\n        return ans;\n    }\n};\n```\n**Please upvote to motivate me in my quest of documenting all leetcode solutions(to help the community). HAPPY CODING:)\nAny suggestions and improvements are always welcome**
[]