O(N*M*LogM)
\n# Code\n\npublic class Solution {\n    public int LargestSubmatrix(int[][] matrix) {\n        int Y = matrix.Length;    //rows count\n        int X = matrix[0
\n# Code\n```\npublic class Solution {\n    public int LargestSubmatrix(int[][] matrix) {\n        int Y = matrix.Length;    //rows count\n        int X = matrix[0].Length; //columns count\n\n        //transform matrix to (matrix[y][x] = count of 1s upper (<y))\n        for (int x = 0; x < X; x++)        \n            for (int y = 1; y < Y; y++)\n                matrix[y][x] = matrix[y][x] == 0 ? 0 : matrix[y - 1][x] + 1;\n\n        int res = 0;  \n        for (int y = 0; y < Y; y++)\n        {\n            //get y-th row and sort it descending\n            Array.Sort(matrix[y], (a, b) => b.CompareTo(a));            \n            for (int x = 0; x < X; x++)\n                res = Math.Max(res, (x + 1) * matrix[y][x]);\n        }\n        return res;\n    }\n}\n```
['C#']