Java 100% Efficient code || comment line by line understable
\n\n# Code\n```\nclass Solution\n {\n   \n // Function to find the size of the largest submatrix containing only 1s\n  \n  public int largestSubmatrix(int[][] m
\n\n# Code\n```\nclass Solution\n {\n   \n // Function to find the size of the largest submatrix containing only 1s\n  \n  public int largestSubmatrix(int[][] matrix) {\n        // Get the number of rows and columns in the matrix\n       \n int m = matrix.length;\n        int n = matrix[0].length;\n        \n        // Initialize the variable to store the result\n        int ans = 0;\n        \n        // Iterate through each row of the matrix\n       \n for (int row = 0; row < m; row++) {\n            // Iterate through each column of the current row\n            for (int col = 0; col < n; col++) {\n                // If the current element is not zero and the row is greater than 0\n               \n if (matrix[row][col] != 0 && row > 0) {\n                    // Update the current element by adding the value of the element above it\n                    matrix[row][col] += matrix[row - 1][col];\n                }\n            }\n            \n            // Create a copy of the current row and sort it in ascending order\n           \n int[] currRow = matrix[row].clone();\n            Arrays.sort(currRow);\n            \n            // Iterate through the sorted row in reverse order\n            for (int i = 0; i < n; i++) {\n                // Update the result by taking the maximum of the current result and\n                // the product of the current element in the sorted row and the width of the submatrix\n                ans = Math.max(ans, currRow[i] * (n - i));\n            }\n        }\n        \n        // Return the final result\n        return ans;\n    }\n}\n\n
['Java']