Simple Prefix Sum Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    pair<int,int> helper(int n)\n    {\n        int n5=0;\n        int n2=0;\n        while(n%5==0)\n        {\n            n5++;\n            n=(n/5);\n        }\n        while(n%2==0)\n        {\n            n2++;\n            n=(n/2);\n        }\n        return {n2,n5};\n    }\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        vector<vector<pair<int,int>>> horizontal(grid.size(),vector<pair<int,int>>(grid[0].size()));\n        vector<vector<pair<int,int>>> vertical(grid.size(),vector<pair<int,int>>(grid[0].size()));\n\n        for(int i=0;i<grid.size();i++)\n        {\n            horizontal[i][0]=helper(grid[i][0]);\n            for(int j=1;j<grid[0].size();j++)\n            {\n                horizontal[i][j]=helper(grid[i][j]);\n                horizontal[i][j].first+=horizontal[i][j-1].first;\n                horizontal[i][j].second+=horizontal[i][j-1].second;\n            }\n        }\n        for(int j=0;j<grid[0].size();j++)\n        {\n            vertical[0][j]=helper(grid[0][j]);\n            for(int i=1;i<grid.size();i++)\n            {\n                vertical[i][j]=helper(grid[i][j]);\n                vertical[i][j].first+=vertical[i-1][j].first;\n                vertical[i][j].second+=vertical[i-1][j].second;\n            }\n        }\n        int ans=0;\n        for(int i=0;i<grid.size();i++)\n        {\n            for(int j=0;j<grid[0].size();j++)\n            {\n                pair<int,int> p = helper(grid[i][j]);\n                pair<int,int> uv = vertical[i][j];\n                pair<int,int> lh = horizontal[i][j];\n\n                pair<int,int> dv = \n                {vertical[grid.size()-1][j].first - uv.first + p.first,vertical[grid.size()-1][j].second - uv.second+p.second};\n                pair<int,int> rh = \n                {horizontal[i][grid[0].size()-1].first - lh.first+p.first, horizontal[i][grid[0].size()-1].second - lh.second+p.second};\n\n                int l1 = min(uv.first+lh.first - p.first,uv.second+lh.second - p.second);\n                int l2 = min(uv.first+rh.first - p.first,uv.second+rh.second - p.second);\n                int l3 = min(uv.first+dv.first - p.first,uv.second+dv.second - p.second);\n                int l4 = min(dv.first+lh.first - p.first,dv.second+lh.second - p.second);\n                int l5 = min(dv.first+rh.first - p.first,dv.second+rh.second - p.second);\n                int l6 = min(rh.first+lh.first - p.first,rh.second+lh.second - p.second);\n                // cout<<i<<" "<<j<<" "<<l1<<l2<<l3<<l4<<l5<<l6<<endl;\n                ans=max(ans,max({l1,l2,l3,l4,l5,l6}));\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']