C++||Largest Submatrix With Rearrangements to Largest Rectangle in Histogram||logic explained
Simple conversion from Largest Submatrix With Rearrangements to Largest Rectangle in Histogram\nIdea:\n\n1.for each a[i][j] cell count number of continuos 1\'s 
**Simple conversion from Largest Submatrix With Rearrangements to Largest Rectangle in Histogram\nIdea:**\n\n1.for each a[i][j] cell count number of continuos 1\'s in its column,so we have column height of a[i][j];\n2.for each row we will sort the row in descending order of column heights since  you are allowed to rearrange the columns of the matrix in any order and for each row apply largest area of histogram concept to find largest area possible by row of column heights.\n    \nA Dry run of above approach    \ne.g. [[0,0,1],\n      [1,1,1],\n      [1,0,1]]\nstep 1:calculating column hegiht for each cell as:\n     [[0,0,1],\n      [1,1,2],\n      [2,0,3]]\n      \nstep 2:for each row sort it in  descending order of column heights and apply gest area of histogram concept\nfor row 1 we have [1,0,0] largest area=1;\nfor row 2 we have [2,1,1] largest area=3;\nfor row 3 we have [3,2,0] largest area=4;\nhence our answer is 4;\n\nHope this help :)\n    Please upvote if this help;\n\n```\n\n\n\nclass Solution {\npublic:\n    int hist(int h[],int n){\n        stack<int> s;\n        //cout<<Jai Shree Ram\n        int i=0,ans=0;\n        while(i<n)\n        {\n            if(s.empty() || h[s.top()]<=h[i])\n            {\n                s.push(i++);\n            }\n            else\n            {\n                int tp=s.top();s.pop();\n                int res=h[tp]*(s.empty()?i:i-s.top()-1);\n                ans=max(ans,res);\n            }\n        }\n        while(!s.empty())\n        {\n            int tp=s.top();s.pop();\n            int res=h[tp]*(s.empty()?i:i-s.top()-1);\n            ans=max(ans,res);\n        }\n        return ans;\n    }\n    int largestSubmatrix(vector<vector<int>>& a) {\n        int n=a.size(),m=a[0].size();\n        int v[n][m];memset(v,0,sizeof(v));\n        for(int i=0;i<m;i++)\n        {\n            int cnt=0;int start,end;\n            for(int j=0;j<n;j++)\n            {\n                if(a[j][i]) cnt++;\n                else cnt=0;\n                v[j][i]=cnt;\n            }\n        }\n        int ans=0;\n        for(int i=0;i<n;i++)\n            sort(v[i],v[i]+m,greater<int>());\n        for(int i=0;i<n;i++)\n        {\n            ans=max(ans,hist(v[i],m));\n        }\n        return ans;\n    }\n};\n```
[]