Java Beginner Friendly Code
Explanation\n Describe your first thoughts on how to solve this problem. \nStep 1: Preprocessing (as given is Hint 1)\nStep 2: Sorting Rows (as given in Hint 2)
# Explanation\n<!-- Describe your first thoughts on how to solve this problem. -->\nStep 1: Preprocessing (as given is Hint 1)\nStep 2: Sorting Rows (as given in Hint 2)\nStep 3: Calculate Area\nIterate through each row and calculate the area for each cell.\n\n# Complexity\n- Time complexity: O(matrix.length * matrix[0].length * log(matrix[0].length))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int largestSubmatrix(int[][] matrix) {\n        // Preprocessing each column to find the number of consecutive ones\n        for(int i=1;i<matrix.length;i++){\n            for(int j=0;j<matrix[0].length;j++){\n                if(matrix[i][j] == 1) {\n                    matrix[i][j] = matrix[i-1][j] + 1;\n                }\n            }\n        }\n        // System.out.println(Arrays.toString(matrix));\n        int maxArea = 0;\n        // Now performing operations on each row to find the answer\n        for(int[] arr : matrix){\n            // Sort the current row\n            Arrays.sort(arr);\n            int k=1;\n            // Find the area\n            for(int i=arr.length-1;i>=0;i--){\n                // Exclude the area where 0 is present\n                if(arr[i] != 0) {\n                    maxArea = Math.max(maxArea, (arr[i] * k));\n                    k++;\n                }\n            }\n        }\n        return maxArea;\n    }\n}\n```
['Array', 'Math', 'Sorting', 'Java']