C++ | Variation of Leetcode 85.Maximal Rectangle
\nclass Solution {\npublic:\n    int largestSubmatrix(vector<vector<int>>& v) {\n        int n=v.size();\n        int m=v[0].size();\n        int res;\n        
```\nclass Solution {\npublic:\n    int largestSubmatrix(vector<vector<int>>& v) {\n        int n=v.size();\n        int m=v[0].size();\n        int res;\n        vector<int> vv(m,0);\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(v[i][j]==1){\n                   vv[j]+=1;\n                }\n                else{\n                    vv[j]=0;\n                }\n            }\n            auto b=vv;//this is the step actually which might be missed\n            sort(b.begin(),b.end());\n            res=max(res,helper(b));\n        }\n        return res;\n    }\n    int helper(vector<int>& heights){\n        int n=heights.size();\n        stack<int> st;\n        vector<int> prevsmaller(n,-1),nextsmaller(n,n);\n        for(int i=0;i<n;i++){\n            while(st.empty()==false and heights[st.top()]>heights[i]){\n                nextsmaller[st.top()]=i;\n                st.pop();\n            }\n            st.push(i);\n        }\n        for(int i=n-1;i>=0;i--){\n            while(st.empty()==false and heights[st.top()]>heights[i]){\n                prevsmaller[st.top()]=i;\n                st.pop();\n            }\n            st.push(i);\n        }\n      \n        int area=0;\n        for(int i=0;i<=n-1;i++){\n            int l=prevsmaller[i];\n            int r=nextsmaller[i];\n            //cout<<l<<" "<<r<<" "<<heights[i]<<endl;\n            //in between l and r we can make a histogram of atleast height: heights[i]\n            area=max(area,(r-l-1)*(heights[i]));\n        }\n        return area;\n    }\n};\n```
[]