Simple solution Using NSR and NSL | stack based solution
\nSame approach as to find maximum area histogram using Nearest smaller to left and Nearest smaller to right, only difference is that maximum area histogram is 
``\nSame approach as to find maximum area histogram using Nearest smaller to left and Nearest smaller to right, only difference is that maximum area histogram is 1D and this is 2D so we start taking by one row at a time and find its area and keep max_area variable which keep track of max and then add it to second row and find again and so on and just keep in mind one thing while you are at current row and adding values to previous check if current level ith value is 0 or 1 if 0 then put 0 because if base is zero which is not possible means bulding can\'t be in air and if 1 then add it...\n``\n\n```\nclass Solution {\npublic:\n    int pseudoIndex;\n    int maximalRectangle(vector<vector<char>>& matrix) {\n       int rows = matrix.size();\n        if (rows == 0) {\n            return 0;\n        }\n        int cols = matrix[0].size();\n        if (cols == 0) {\n            return 0;\n        }\n        vector<int>histogram(cols,0);\n        \n        int res = 0;\n        \n        for (int i = 0; i< rows; i++) {\n            for (int j = 0; j< cols; j++) {\n                if (matrix[i][j] == \'0\') {\n                    histogram[j] = 0;\n                }\n                else {\n                    histogram[j] += (matrix[i][j] - \'0\');\n                }\n            }\n            int area = largestRectangleArea(histogram);\n            \n            res = max(area, res);\n        }\n        return res;\n    }\n    \n    int largestRectangleArea(vector<int>& heights) {\n        \n        if(heights.size() == 0)\n            return 0;\n        //we store index of nearest smaller to left of i\n        vector<int> nsl = NearestSmallerToLeft(heights);\n        //we store index of nearest smaller to right of i\n        vector<int> nsr = NearestSmallerToRight(heights);\n        \n        //find the max area possible\n        int max_area = INT_MIN,area;\n        for(int i = 0; i < heights.size(); i++)\n        {\n            area = (nsr[i]-nsl[i]-1)*heights[i];\n            max_area = max(area,max_area);\n        }\n        return max_area;\n    }\n    \n   vector<int> NearestSmallerToLeft(vector<int> temp)\n    {\n        stack<pair<int,int>> st;\n        vector<int> left;\n        pseudoIndex = -1;\n        for(int i = 0; i < temp.size();i++)\n        {\n            if(st.empty())\n                left.push_back(pseudoIndex);\n            else if(!st.empty() && st.top().first < temp[i])\n                left.push_back(st.top().second);\n            else if(!st.empty() && st.top().first >= temp[i])\n            {\n                while(!st.empty() && st.top().first >= temp[i])\n                {\n                    st.pop();\n                }\n                if(st.empty())\n                {\n                    left.push_back(-1);\n                }\n                else left.push_back(st.top().second);\n            }\n        st.push({temp[i],i});\n        }\n    return left;\n    }\n\n    vector<int> NearestSmallerToRight(vector<int> temp)\n    {\n        stack<pair<int,int>> st;\n        vector<int> right;\n        pseudoIndex = temp.size();    \n        for(int i = temp.size() - 1; i >= 0; i--)\n        {\n            if(st.empty())\n            {\n                right.push_back(pseudoIndex);\n            }\n            else if(!st.empty() && st.top().first < temp[i])\n                right.push_back(st.top().second);\n            else if(!st.empty() && st.top().first >= temp[i])\n            {\n                while(!st.empty() && st.top().first >= temp[i])\n                    st.pop();\n                if(st.empty())\n                    right.push_back(pseudoIndex);\n                else \n                    right.push_back(st.top().second);\n            }\n        st.push({temp[i],i});\n        }\n        reverse(right.begin(),right.end());\n        return right;\n    }\n};\n```
['Stack']