✅ Beats 96.02% 🚀 c++ code 🔥
Intuition\n- I need all indexes in result matrix with only ones.\n\n# Approach\n- Save for everyone in the matrix, the number of consecutive ones before it.\n- 
# Intuition\n- I need all indexes in result matrix with only ones.\n\n# Approach\n- Save for everyone in the matrix, the number of consecutive ones before it.\n- Take these numbers and sort it in ascending order. \n- Iterate on these numbers from back to front to get the greater high every time.\n- Take the minimum every time for this numbers to get the lowest high.\n- The take maximum multiplication with man and the current number.\n\n# Complexity\n- Time complexity:\n- $$O(m*nlog(n))$$\n\n- Space complexity:\n- $$O(m*n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int largestSubmatrix(vector<vector<int>>& matrix) {\n        ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);\n        int ans=0,n=matrix.size(),m=matrix[0].size(),i,j,mn,cnt=0;\n        vector<vector<int>>use(n,vector<int>(m));\n        for(i=0;i<m;i++)\n            if(matrix[0][i]==1)\n                use[0][i]=1,cnt++;\n        ans=max(ans,cnt);\n        int help[100000];\n        for(i=1;i<n;i++){\n            cnt=0;\n            for(j=0;j<m;j++)\n                if(matrix[i][j]==1)\n                    use[i][j]=use[i-1][j]+1,help[cnt++]=use[i][j];\n            sort(help,help+cnt);\n            mn=1e9;\n            for(j=cnt-1;j>=0;j--)\n                mn=min(mn,help[j]),ans=max(ans,(cnt-j)*mn);\n        }\n        return ans;\n    }\n};\n```
['Math', 'Dynamic Programming', 'Sorting', 'Matrix', 'C++']