C++ || Commented Solution || Very Easy to Understand
`\nclass Solution {\npublic:\n    \n    int twocnt(int num)\n    {\n        int cnt = 0;\n        while(num % 2 == 0)\n        {\n            cnt++;\n          
```\nclass Solution {\npublic:\n    \n    int twocnt(int num)\n    {\n        int cnt = 0;\n        while(num % 2 == 0)\n        {\n            cnt++;\n            num /= 2;\n        }\n        return cnt;\n    }\n    \n    int fivecnt(int num)\n    {\n        int cnt = 0;\n        while(num % 5 == 0)\n        {\n            cnt++;\n            num /= 5;\n        }\n        return cnt;\n    }\n    \n    vector<vector<int>> rot(vector<vector<int>> &grid) // rotating the matrix clockwise\n    {\n        int n = grid.size();\n        int m = grid[0].size();\n        \n        vector<vector<int>> temp(m, vector<int>(n));\n        \n        for(int i = 0; i < n; i++)\n        {\n            for(int j = 0; j < m; j++)\n            {\n                temp[j][n-1-i] = grid[i][j];\n            }\n        }\n        return temp;\n    }\n    \n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        \n        int maxans = 0;\n        for(int q = 0; q < 4; q++) // repeat for all 4 orientations of the matrix\n        {\n            int n = grid.size();\n            int m = grid[0].size();\n            \n            vector<vector<pair<int,int>>> vals(n, vector<pair<int,int>>(m)); // suffix sum from right to left for each row\n            \n            for(int i = 0; i < n; i++)\n            {\n                int twos = 0, fives = 0;\n                for(int j = m - 1; j >= 0; j--)\n                {\n                    int curtwocnt = twocnt(grid[i][j]);\n                    int curfivecnt = fivecnt(grid[i][j]);\n                    \n                    twos += curtwocnt;\n                    fives += curfivecnt;\n                    \n                    vals[i][j].first = twos;\n                    vals[i][j].second = fives; \n                }\n            }\n            \n            for(int j = 0; j < m; j++)\n            {\n                int twos = 0, fives = 0;\n                for(int i = 0; i < n; i++)\n                {\n                    int curtwos = twos + vals[i][j].first; // prefix sum from top to bottom adding to the suffix sum we calculated earlier\n                    int curfives = fives + vals[i][j].second;\n                    \n                    int curans = min(curtwos, curfives);\n                   \n                    maxans = max(maxans, curans);\n                    \n                    int curtwocnt = twocnt(grid[i][j]);\n                    int curfivecnt = fivecnt(grid[i][j]);\n                    \n                    twos += curtwocnt;\n                    fives += curfivecnt;\n                    \n                }\n            }\n            \n            \n            grid = rot(grid); // rotating the grid and repeating\n        }\n        \n        return maxans;\n    }\n};\n``
['C', 'Prefix Sum']