JAVA | Simple 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)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maxTrailingZeros(int[][] grid) {\n        int[][][] t = new int[grid.length][grid[0].length][8];\n        int n = grid.length;\n        int m = grid[0].length;\n\n        int[][][] tf = new int[n][m][2];\n        for(int i = 0; i<n;i++) {\n            for(int j = 0 ; j<m ;j++) {\n                int two = 0;\n                int five = 0;\n                int k = grid[i][j];\n                while(k%2==0){\n                    k/=2;\n                    two++;\n                }\n                while(k%5==0){\n                    k/=5;\n                    five++;\n                }\n                tf[i][j][0] = two;\n                tf[i][j][1] = five;\n            }\n        }\n        for(int i = 0; i<n;i++) {\n            int two = 0;\n            int five = 0;\n            for(int j = 0; j<m;j++) {\n                int k = grid[i][j];\n                while(k%2 == 0) {\n                    two++;\n                    k=k/2;\n                }\n                while(k%5 == 0) {\n                    five++;\n                    k=k/5;\n                }\n                t[i][j][0] = two;\n                t[i][j][1] = five;\n            }\n        }\n\n\n        for(int i = 0; i<n;i++) {\n            int two = 0;\n            int five = 0;\n            for(int j = m-1; j>=0;j--) {\n                int k = grid[i][j];\n                while(k%2 == 0) {\n                    two++;\n                    k=k/2;\n                }\n                while(k%5 == 0) {\n                    five++;\n                    k=k/5;\n                }\n                t[i][j][2] = two;\n                t[i][j][3] = five;\n            }\n        }\n         for(int i = 0; i<m;i++) {\n            int two = 0;\n            int five = 0;\n            for(int j = 0; j<n;j++) {\n                int k = grid[j][i];\n                while(k%2 == 0) {\n                    two++;\n                    k=k/2;\n                }\n                while(k%5 == 0) {\n                    five++;\n                    k=k/5;\n                }\n                t[j][i][4] = two;\n                t[j][i][5] = five;\n            }\n        }\n        for(int i = 0; i<m;i++) {\n            int two = 0;\n            int five = 0;\n            for(int j = n-1; j>=0;j--) {\n                int k = grid[j][i];\n                while(k%2 == 0) {\n                    two++;\n                    k=k/2;\n                }\n                while(k%5 == 0) {\n                    five++;\n                    k=k/5;\n                }\n                t[j][i][6] = two;\n                t[j][i][7] = five;\n            }\n        }\n        int[][] ans = new int[n][m];\n        int a = 0;\n         for(int i = 0; i<n; i++) {\n            for(int j = 0; j<m ;j++) {\n                ans[i][j] = Math.max(ans[i][j],Math.min(t[i][j][0] + t[i][j][4] - tf[i][j][0],t[i][j][1] + t[i][j][5] - tf[i][j][1])); //3\n                ans[i][j] = Math.max(ans[i][j],Math.min(t[i][j][0] + t[i][j][6]- tf[i][j][0],t[i][j][1] + t[i][j][7]- tf[i][j][1]));\n                ans[i][j] = Math.max(ans[i][j],Math.min(t[i][j][2] + t[i][j][4]- tf[i][j][0],t[i][j][3] + t[i][j][5]- tf[i][j][1]));\n                ans[i][j] = Math.max(ans[i][j],Math.min(t[i][j][2] + t[i][j][6]- tf[i][j][0],t[i][j][3] + t[i][j][7]- tf[i][j][1]));\n            a = Math.max(a,ans[i][j]);\n            }\n         }\n         return a;\n        \n    }\n}\n```
['Java']