CPP || 99 %faster and 99%memory
class Solution {\npublic:\n    \n    pairfind_factor(int n)\n    {   \n        int two=0,five=0;\n        while(n%5==0)\n        {\n            five++;\n       
class Solution {\npublic:\n    \n    pair<int,int>find_factor(int n)\n    {   \n        int two=0,five=0;\n        while(n%5==0)\n        {\n            five++;\n            n/=5;\n        }\n        \n        while(n%2==0)\n        {\n            two++;\n            n/=2;\n            \n        }\n        \n        return {two,five};\n    }\n    int maxTrailingZeros(vector<vector<int>>& grid) \n    {\n        int n=grid.size(),m=grid[0].size();\n        \n        int factor[n][m][2];\n        \n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {   \n                pair<int,int>p=find_factor(grid[i][j]);\n                factor[i][j][0]=p.first;\n                factor[i][j][1]=p.second;\n            }\n        }\n        \n        \n        int row[n][m][2];\n        int col[n][m][2];\n        \n        for(int i=0;i<n;i++)\n        {\n            int two=0,five=0;\n            \n            for(int j=0;j<m;j++)\n            {\n                row[i][j][0]=two+factor[i][j][0];\n                two=row[i][j][0];\n                row[i][j][1]=five+factor[i][j][1];\n                five=row[i][j][1];\n            }\n        }\n        \n         for(int j=0;j<m;j++)\n        {\n            int two=0,five=0;\n            \n            for(int i=0;i<n;i++)\n            {\n                col[i][j][0]=two+factor[i][j][0];\n                two=col[i][j][0];\n                col[i][j][1]=five+factor[i][j][1];\n                five=col[i][j][1];\n            }\n        }\n        \n        \n        \n        \n        \n        int ans=0;\n        \n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                int a=(i>0)?col[i-1][j][0]:0;\n                int b=(i!=n-1)?col[n-1][j][0]-col[i][j][0]:0;\n                int c=(i>0)?col[i-1][j][1]:0;\n                int d=(i!=n-1)?col[n-1][j][1]-col[i][j][1]:0;\n                \n                int p=(j>0)?row[i][j-1][0]:0;\n                int q=(j!=m-1)?row[i][m-1][0]-row[i][j][0]:0;\n                int r=(j>0)?row[i][j-1][1]:0;\n                int s=(j!=m-1)?row[i][m-1][1]-row[i][j][1]:0;\n                \n                \n                ans=max(ans,min(a+p+factor[i][j][0],c+r+factor[i][j][1]));\n                ans=max(ans,min(a+q+factor[i][j][0],c+s+factor[i][j][1]));\n                ans=max(ans,min(b+p+factor[i][j][0],d+r+factor[i][j][1]));\n                ans=max(ans,min(b+q+factor[i][j][0],d+s+factor[i][j][1]));\n                \n                \n            }\n        \n        }\n        \n        \n        return ans;\n    }\n};
[]