Easy to Read || Beginner friendly || No Fluff || C++/Java/Python
Treat every column in the matrix as a height bar, where the base of that height represents total number of consecutives ones above it included himself. \n\n\n  
Treat every column in the matrix as a height bar, where the base of that height represents total number of consecutives ones above it included himself. \n\n```\n       [[0,0,1],\n        [1,1,1],\n        [1,0,1]]\nheight->[2,0,3] -> sort -> [3,2,0] -> \n```\n\nNow iterate over this sorted row and consider the largest submatrix from it -> at col 0 height of 3. here the base is 3 but with that base we have only one col so area 3.  \n\nNow check at col 1 with base height as 2. So we have two cols where base hight can be 2 so area=4. \n\nAt col 3 the base height should be 0 and thats the only col which has the base heght 0, so area =0. \n\nThus the max ans is 4.\n\n**C++:**\n```cpp\nclass Solution {\npublic:\n    int largestSubmatrix(vector<vector<int>>& matrix) {\n        int m = matrix.size(), n = matrix[0].size();\n        int ans = 0;\n        for (int row = 0; row<m; row++){\n            for(int col = 0; col<n; col++){\n                if(matrix[row][col] != 0 && row > 0){\n                    matrix[row][col] += matrix[row-1][col];\n                }\n            }\n            \n            vector<int> currRow = matrix[row];\n            sort(currRow.begin(), currRow.end(), greater());\n            for(int i=0; i<n;i++){\n                ans = max(ans, currRow[i] * (i+1));\n            }\n        }\n        return ans;\n    }\n};\n```\n\n**Java:**\n```java\nclass Solution {\n    public int largestSubmatrix(int[][] matrix) {\n        int m = matrix.length;\n        int n = matrix[0].length;\n        int ans = 0;\n        \n        for (int row = 0; row < m; row++) {\n            for (int col = 0; col < n; col++) {\n                if (matrix[row][col] != 0 && row > 0) {\n                    matrix[row][col] += matrix[row - 1][col];\n                }\n            }\n            \n            int[] currRow = matrix[row].clone();\n            Arrays.sort(currRow);\n            for (int i = 0; i < n; i++) {\n                ans = Math.max(ans, currRow[i] * (n - i));\n            }\n        }\n        \n        return ans;\n    }\n}\n```\n\n**Python:**\n```python\nclass Solution(object):\n    def largestSubmatrix(self, matrix):\n        m, n = len(matrix), len(matrix[0])\n        ans = 0\n        \n        for row in range(m):\n            for col in range(n):\n                if matrix[row][col] != 0 and row > 0:\n                    matrix[row][col] += matrix[row - 1][col]\n            \n            curr_row = sorted(matrix[row], reverse=True)\n            \n            for i in range(n):\n                ans = max(ans, curr_row[i] * (i + 1))\n                \n        return ans\n```
['Array', 'Math', 'Sorting', 'Matrix']