C++ || Prefix Sum || Easy to Understand || Beats 100% Space and Time
Explanation:\n\t Consider every element of the grid as the corner point of the cornered path. Now there can be four possible ways of making an \'L\' Shape figur
* **Explanation:**\n\t* Consider every element of the grid as the corner point of the cornered path. Now there can be four possible ways of making an \'L\' Shape figure. \n\t* \tWe need to make **prefix matrices of pairs** to store the prefix sum of exponent of 5\'s and 2\'s of each element in the grid, otherwise if we store the whole multiplication result, then it would create integer overflow.\n\t * And **we need only two prefix matrices**, because the result of other two sides will be calculated by subtracting from total sum of that side. \t\n\t * To get the count of trailing 0\'s we have to take the minimum of count of 5 and 2 from the pairs.\n\t * The case of 0 turns that is horizontally straight or vertically straight path will be handled automatically by prefix sum matrix.\n\n* **Time Complexity: O(MxN)**\n* **Space Complexity: O(MxN)**\n\n```\n\t//to get the exponent of 5 and 2 in the number\n    pair<int,int> getPair(int x){\n        int five = 0, two = 0;\n        while(x % 5 == 0){\n            five++; x /= 5;\n        }\n        while(x % 2 == 0){\n            two++; x /= 2;\n        }\n        return {five,two};\n    } \n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int r = grid.size(), c = grid[0].size(), ans = 0;\n        vector<vector<pair<int,int>>>top(r, vector<pair<int,int>>(c,{0,0})), left(r, vector<pair<int,int>>(c,{0,0}));\n        \n        //top[i][j] will store sum of exponent of 5\'s and 2\'s from grid[0][j] to grid[i][j]\n        for(int i = 0; i < r; i++){\n            for(int j = 0; j < c; j++){\n                if(i == 0) top[i][j] = getPair(grid[i][j]);\n                else{\n                    pair<int,int>p = getPair(grid[i][j]);\n                    top[i][j].first = top[i-1][j].first + p.first;\n                    top[i][j].second = top[i-1][j].second + p.second;\n                }\n            }\n        }\n        //left[i][j] will store sum of exponent of 5\'s and 2\'s from grid[i][0] to grid[i][j]\n        for(int i = 0; i < r; i++){\n            for(int j = 0; j < c; j++){\n                if(j == 0) left[i][j] = getPair(grid[i][j]); \n                else{\n                    pair<int,int>p = getPair(grid[i][j]);\n                    left[i][j].first = left[i][j-1].first + p.first;\n                    left[i][j].second = left[i][j-1].second + p.second;\n                }\n            }\n        }\n        for(int i = 0; i < r; i++){\n            for(int j = 0; j < c; j++){\n                pair<int,int>down, right;\n                pair<int,int>curr = getPair(grid[i][j]);\n                \n                down.first = top[r-1][j].first - top[i][j].first, down.second = top[r-1][j].second - top[i][j].second;\n                right.first = left[i][c-1].first - left[i][j].first, right.second = left[i][c-1].second - left[i][j].second;\n                                \n                //four cases ---> (down,left), (down,right), (top,left), (top,right)\n                ans = max(ans, min(down.first + left[i][j].first, down.second + left[i][j].second));\n                ans = max(ans, min(down.first + right.first + curr.first, down.second + right.second + curr.second));\n                ans = max(ans, min(top[i][j].first + left[i][j].first - curr.first, top[i][j].second + left[i][j].second - curr.second));\n                ans = max(ans, min(top[i][j].first + right.first, top[i][j].second + right.second));\n            }\n        }\n        return ans;\n    }\n```
['C', 'Matrix', 'Prefix Sum']