Variation of MAH [C++] || A bit long but easy solution
\nclass Solution {\npublic:\n\t\tvector<int> NSL(vector<int> heights){ // Function to find indices of next smallest left element\n        vector<int> left;\n   
```\nclass Solution {\npublic:\n\t\tvector<int> NSL(vector<int> heights){ // Function to find indices of next smallest left element\n        vector<int> left;\n        stack<pair<int,int>> st;\n        for(int i=0;i<heights.size();i++){\n            if(st.empty())\n                left.push_back(-1);\n            else if(!st.empty() && st.top().first<heights[i])\n                left.push_back(st.top().second);\n            else if(!st.empty() && st.top().first>=heights[i]){\n                while(!st.empty() && st.top().first>=heights[i])\n                    st.pop();\n                if(st.empty())\n                    left.push_back(-1);\n                else \n                    left.push_back(st.top().second);\n            }\n            st.push({heights[i],i});\n        }\n        return left;\n    }\n    vector<int> NSR(vector<int> heights){  // Function to find indices of next smallest right element\n        vector<int> right;\n        stack<pair<int,int>> st;\n        for(int i=heights.size()-1;i>=0;i--){\n            if(st.empty())\n                right.push_back(heights.size());\n            else if(!st.empty() && st.top().first<heights[i])\n                right.push_back(st.top().second);\n            else if(!st.empty() && st.top().first>=heights[i]){\n                while(!st.empty() && st.top().first>=heights[i])\n                    st.pop();\n                if(st.empty())\n                    right.push_back(heights.size());\n                else \n                    right.push_back(st.top().second);\n            }\n            st.push({heights[i],i});\n        }\n        reverse(right.begin(),right.end());\n        return right;\n    }\n    int MAH(vector<int>& heights) {  //Function to find maximum area of histogram\n        vector<int> right;\n        vector<int> left;\n        \n        right=NSR(heights);\n        left=NSL(heights);\n        \n        vector<int> width;\n        int mx=0;\n        for(int i=0;i<left.size();i++){\n            width.push_back(right[i]-left[i]-1);\n        }\n        \n        for(int i=0;i<heights.size();i++){\n            mx=max(mx,heights[i]*width[i]);\n        }\n        \n        return mx;\n    }\n    int maximalRectangle(vector<vector<char>>& matrix) {  // Finally......our required Maximal Rectangle Function\n        int n=matrix.size();\n        if(n == 0){\n            return 0;\n        }\n        int m=matrix[0].size();\n        vector<int> v;\n        for(int j=0;j<m;j++){\n            v.push_back(matrix[0][j]-\'0\');\n        }\n        int mx= MAH(v);\n        for(int i=1;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(matrix[i][j]==\'0\')\n                    v[j]=0;\n                else\n                    v[j]=v[j]+(matrix[i][j]-\'0\');\n            }\n            mx=max(mx,MAH(v));\n        }\n        return mx;\n    }\n};\n```
['Stack', 'C', 'C++']