Easy explanation with example | Space complexity O(1) | beats 90% C# users
Intuition\nSubmatrix would either be a squre matrix or rectangular matrix, so we need to traverse each column and check the number of consicutive ones and then 
# Intuition\nSubmatrix would either be a squre matrix or rectangular matrix, so we need to traverse each column and check the number of consicutive ones and then arrange row elements to get the biggest submatrix possible.\n\n# Approach\n### Step 1\nTraverse each column and modify row elements in such a way that if \'i\' element, matrix[i][c], is 1, then the \'i+1\' element of same column, matrix[i+1][c] will be 2 else 0.\nThis is how we will get longest streak in each column.\n### Step 2\nNow for each row, arrange the elements in decending order and multiply the element with column number of matrix (i.e. (c + 1) * matrix[r][c]). Maximum of it will give us the biggest subMatrix area.\n\n## Example:\n#### given matrix: \n                    [[0, 0, 1],\n                     [1, 1, 1],\n                     [1, 0, 1]]\n#### After step 1:\n\n                   [[0, 0, 1],\n                    [1, 1, 2],\n                    [2, 0, 3]]\n#### Step 3:\n\n                    [1*1, 0*2, 0*3]    [1,0,0]\n                    [2*1, 1*2, 1*3] =  [2,2,3]\n                    [3*1, 2*2, 0*3]    [3,4,0]\nSo, the Size of biggest submatrix is 4.\n\n# Complexity\n- Time complexity:\nO(M*N*log(M)) - nested loops and Sorting of row elements.\n\n- Space complexity:\nO(1) - As we are making change in given matrix only, we only need some integer variables \n\n# Code\n```\npublic class Solution {\n    public int LargestSubmatrix(int[][] matrix) {\n        int rows = matrix.Length;    \n        int cols = matrix[0].Length;\n\n        for (int c = 0; c < cols; c++)        \n            for (int r = 1; r < rows; r++)\n                matrix[r][c] = matrix[r][c] == 0 ? 0 : matrix[r - 1][c] + 1;\n\n        int ans = 0;  \n        for (int r = 0; r < rows; r++)\n        {\n            Array.Sort(matrix[r], (a, b) => b.CompareTo(a));            \n            for (int c = 0; c < cols; c++)\n                ans = Math.Max(ans, (c + 1) * matrix[r][c]);\n        }\n        return ans;\n    }\n}\n```
['C#']