C++ || two stacks solution || simple
leetcode 84-> same approach\n https://leetcode.com/problems/largest-rectangle-in-histogram/discuss/1825607/C++-oror-two-stack-solution-oror-simple-oror-previous
leetcode 84-> same approach\n https://leetcode.com/problems/largest-rectangle-in-histogram/discuss/1825607/C++-oror-two-stack-solution-oror-simple-oror-previous-smaller-element-oror-next-smaller-element\n \n ```\n class Solution {\n    int fun(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> nsl,nsr;\n        stack<pair<int,int>> s1,s2;\n\n        for(int i=0;i<nums.size();i++)\n        {\n            if(s1.empty())\n                nsl.push_back(-1);\n            else{\n                while(!s1.empty() && s1.top().first>=nums[i])\n                    s1.pop();\n                if(s1.empty())\n                    nsl.push_back(-1);\n                else\n                    nsl.push_back(s1.top().second);\n            }\n            s1.push({nums[i],i});\n        }\n\t\t\n        for(int i=n-1;i>=0;i--)\n        {\n            if(s2.empty())\n                nsr.push_back(n);\n            else{\n                while(!s2.empty() && s2.top().first>=nums[i])\n                    s2.pop();\n                if(s2.empty())\n                    nsr.push_back(n);\n                else\n                    nsr.push_back(s2.top().second);\n            }\n            s2.push({nums[i],i});\n        }\n        reverse(nsr.begin(),nsr.end());\n\t\t\n        int res = INT_MIN;\n        int val=0;\n        for(int i=0;i<nums.size();i++)\n        {\n            val = (nsr[i]-nsl[i]-1)*nums[i];\n            res = max(res,val);\n        }\n        return res;\n    }\npublic:\n    int maximalRectangle(vector<vector<char>>& matrix) {\n        int row = matrix.size();\n        int column = matrix[0].size();\n        vector<int> arr(column,0);\n        int res = INT_MIN;\n        for(int i = 0;i<row;i++)\n        {\n            for(int j=0;j<column;j++)\n            {\n                if(matrix[i][j]==\'0\')\n                    arr[j]=0;\n                else\n                    arr[j]++;\n            }\n            res = max(res,fun(arr));\n        }\n        return res;\n    }\n};\n```
[]