Easy to Understand in C++ || Histogram Approach || D.p
class Solution {\npublic:\n    \n    int maxAreaHistogram(vector& heights)\n    {\n        int n = heights.size();\n        vector nsl(n),psl(n);\n        \n   
class Solution {\npublic:\n    \n    int maxAreaHistogram(vector<int>& heights)\n    {\n        int n = heights.size();\n        vector<int> nsl(n),psl(n);\n        \n        stack<int> s;\n        \n        for(int i=n-1;i>=0;i--){\n            while(!s.empty() && heights[s.top()]>=heights[i]){\n                s.pop();\n            }\n            nsl[i] = s.empty() ? n : s.top();\n            s.push(i);\n        }\n        \n        while(!s.empty()){\n            s.pop();\n        }\n        \n        for(int i=0;i<n;i++){\n            while(!s.empty() && heights[s.top()]>=heights[i]){\n                s.pop();\n            }\n            psl[i] = s.empty() ? -1: s.top();\n            s.push(i);\n        }\n        \n        int ans = INT_MIN;\n        for(int i=0;i<n;i++){\n            ans = max(ans,(nsl[i]-psl[i]-1)*(heights[i]));\n        }\n        \n        return ans;\n    }\n    \n    int maximalRectangle(vector<vector<char>>& matrix) {\n        \n        if( matrix.empty() ) return 0;\n        \n        int rowSize = matrix.size();\n        int colSize = matrix[0].size();\n        int maxArea = 0;\n        \n        vector<vector<int>>grid(rowSize,vector<int>(colSize,0));\n        \n        for( int i = 0; i < rowSize; i++ )\n        {\n            for( int j = 0; j < colSize; j++ )\n            {\n                grid[i][j] = ( matrix[i][j] == \'1\' ? 1 : 0 );\n                if( i != 0 && grid[i][j] == 1 ) grid[i][j] += grid[i-1][j];\n            }\n            \n            int tmpAns = maxAreaHistogram(grid[i]);\n            maxArea = max(maxArea,tmpAns);\n        }\n\n        return maxArea;\n        \n    }\n};
['Dynamic Programming']