C++ easy solution O(n*m) solution
\n\n# Complexity\n- Time complexity:o(nm)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:o(nm)\n Add your space complexity here, e.g. O(n) \n
\n\n# Complexity\n- Time complexity:o(n*m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:o(n*m)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n//min(numberof5,numberof2)\n//[i][j][4][1]\nclass Solution {\npublic:\n    pair<int,int> check(int a){\n        int cnt2=0,cnt5=0;\n        // while(a%10==0){cnt10++,a/=10;}\n        while(a%2==0){cnt2++,a/=2;}\n        while(a%5==0){cnt5++,a/=5;}\n        return {cnt2,cnt5};\n    }\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int i,j,n=grid.size(),m=grid[0].size();\n        int dp[n][m][4][2];\n\n        for(i=0;i<n;i++){\n            for(j=0;j<m;j++){\n                auto [cnt2,cnt5]=check(grid[i][j]);\n                dp[i][j][0][0]=(j==0)?cnt2:dp[i][j-1][0][0]+cnt2;\n                dp[i][j][0][1]=(j==0)?cnt5:dp[i][j-1][0][1]+cnt5;\n\n                dp[i][j][2][0]=(i==0)?cnt2:dp[i-1][j][2][0]+cnt2;\n                dp[i][j][2][1]=(i==0)?cnt5:dp[i-1][j][2][1]+cnt5;\n\n                auto tp =check(grid[i][m-j-1]);\n                cnt2=tp.first,cnt5=tp.second;\n                dp[i][m-j-1][1][0]=(j==0)?cnt2:dp[i][m-j][1][0]+cnt2;\n                dp[i][m-j-1][1][1]=(j==0)?cnt5:dp[i][m-j][1][1]+cnt5;\n\n                tp=check(grid[n-i-1][j]);\n                cnt2=tp.first,cnt5=tp.second;\n                dp[n-i-1][j][3][0]=(i==0)?cnt2:dp[n-i][j][3][0]+cnt2;\n                dp[n-i-1][j][3][1]=(i==0)?cnt5:dp[n-i][j][3][1]+cnt5;\n\n            }\n        }\n        int mx=0;\n\n        for(i=0;i<n;i++){\n            for(j=0;j<m;j++){\n                auto [cnt2,cnt5]=check(grid[i][j]);\n                for(int k1=0;k1<4;k1++){\n                    for(int k2=k1+1;k2<4;k2++){           \n                            mx=max(mx,min(dp[i][j][k1][0]+dp[i][j][k2][0]-cnt2\n                            ,dp[i][j][k1][1]+dp[i][j][k2][1]-cnt5));\n                    }\n                }\n\n            }\n        }\n\n\n\n        return mx;\n\n\n    }\n};\n```
['C++']