Easy || Prerequisites || Happy Coding
There are two prerequisites for this problem: the maximal square and the maximal rectangle. Once you understand these concepts, this question becomes relatively
There are two prerequisites for this problem: the maximal square and the maximal rectangle. Once you understand these concepts, this question becomes relatively straightforward to grasp and solve.\n\n# Code\n```\n\n\nclass Solution {\npublic:\n    int largestSubmatrix(vector<vector<int>>& matrix) {\n        int m = matrix.size();\n        int n = matrix[0].size();\n        vector<vector<int>> dp(m, vector<int>(n, 0));\n\n        // Preprocess the matrix to calculate the height of consecutive 1\'s ending at each position\n        for (int i = 0; i < m; i++) {\n            for (int j = 0; j < n; j++) {\n                if (matrix[i][j] == 1) {\n                    dp[i][j] = (i == 0) ? 1 : dp[i - 1][j] + 1;\n                }\n            }\n        }\n\n        int ans = 0;\n        // Sort and calculate the area for each column\n        for (int i = 0; i < m; i++) {\n            sort(dp[i].begin(), dp[i].end(), greater<int>());\n            for (int j = 0; j < n; j++) {\n                ans = max(ans, dp[i][j] * (j + 1));\n            }\n        }\n\n        return ans;\n    }\n};\n\n```
['C++']