C++ || Self Explanatory/More Readable Code || Prefix Sum
\n// Trailing Zeros => Count of 10\'s in a number => 10 = 2*5 => minimum (sum of 2 exponents, sum of 5 exponents)\n// Apporach : Prefix Sum of Count of 2\'s and
```\n// Trailing Zeros => Count of 10\'s in a number => 10 = 2*5 => minimum (sum of 2 exponents, sum of 5 exponents)\n// Apporach : Prefix Sum of Count of 2\'s and 5\'s + Suffix Sum of Count of 2\'s and 5\'s | Time - O(4*m*n), Space - O(2*m*n)\n\nclass Pair{\npublic:\n    int countOfTwo;\n    int countOfFive;\n    \n    Pair(){\n        countOfTwo = 0;\n        countOfTwo = 0;\n    }\n    \n    Pair(int two, int five){\n        countOfTwo = two;\n        countOfFive = five;\n    }\n};\n\nclass Solution {\npublic:\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int m = grid.size();\n        int n = grid[0].size();\n        \n        vector<vector<Pair>> prefix(m, vector<Pair>(n));\n        vector<vector<Pair>> suffix(m, vector<Pair>(n));\n        \n        // Find the Prefix Sum of Count of 2\'s and 5\'s \n        for(int i=0; i<m; i++){\n            for(int j=0; j<n; j++){\n                prefix[i][j]  = findCountTwoAndFive(grid[i][j]);\n                \n                if(j!=0){\n                    prefix[i][j].countOfTwo += prefix[i][j-1].countOfTwo;\n                    prefix[i][j].countOfFive += prefix[i][j-1].countOfFive;\n                }\n            }\n        }\n        \n        // Find the Suffix Sum of Count of 2\'s and 5\'s \n        for(int i=0; i<m; i++){\n            for(int j=n-1; j>=0; j--){\n                suffix[i][j]  = findCountTwoAndFive(grid[i][j]);\n                \n                if(j!=n-1){\n                    suffix[i][j].countOfTwo += suffix[i][j+1].countOfTwo;\n                    suffix[i][j].countOfFive += suffix[i][j+1].countOfFive;\n                }\n            }\n        }\n        \n        //                                                        __   __\n        // Traverse the each valid concerned Path => |__ ,  __| ,  |  ,|  \n        // and calculate the trailing zeros and then take max of it\n        // We\'re traversing each column and then each row\n        \n        // First Traverse the concerned Path  of type:|__ ,  __|\n        int ans = 0;\n        for(int i=0; i<n; i++){\n            int count2 = 0, count5 = 0;\n            for(int j=0; j<m; j++){\n                \n                ans = max(ans, min(count2 + prefix[j][i].countOfTwo, count5 + prefix[j][i].countOfFive));\n                ans = max(ans, min(count2 + suffix[j][i].countOfTwo, count5 + suffix[j][i].countOfFive));\n                \n                Pair p = findCountTwoAndFive(grid[j][i]);\n                count2 += p.countOfTwo, count5 += p.countOfFive;\n            }\n        }\n        \n         //                                                        __   __\n        // Second Traverse the concerned Path  of type:             | , | \n        for(int i=0; i<n; i++){\n            int count2 = 0, count5 = 0;\n            for(int j=m-1; j>=0; j--){\n                \n                ans = max(ans, min(count2 + prefix[j][i].countOfTwo, count5 + prefix[j][i].countOfFive));\n                ans = max(ans, min(count2 + suffix[j][i].countOfTwo, count5 + suffix[j][i].countOfFive));\n                \n                Pair p = findCountTwoAndFive(grid[j][i]);\n                count2 += p.countOfTwo, count5 += p.countOfFive;\n            }\n        }\n        \n        // Now return ans\n        return ans;\n    }\nprivate:\n    Pair findCountTwoAndFive(int num){\n        int two = 0, five = 0;\n        while(num%2==0){\n            two++;\n            num /= 2;\n        }\n                \n        while(num%5==0){\n            five++;\n            num /= 5;\n        }\n                \n        return Pair(two, five);\n    }\n};\n```
['C']