✅Easy solution || ✅Short & Simple || ✅Best Method || ✅Easy-To-Understand
\n# Code\n\nclass Solution {\npublic:\n    int largestRectangleArea(vector<int>& heights) {\n        stack<int> st;\n        int n=heights.size();\n        vect
\n# Code\n```\nclass Solution {\npublic:\n    int largestRectangleArea(vector<int>& heights) {\n        stack<int> st;\n        int n=heights.size();\n        vector<int> left(n);\n        vector<int> ryt(n);\n        for(int i=0;i<n;i++)\n        {\n            while(!st.empty() && heights[i]<=heights[st.top()])\n                            st.pop();\n            if(st.empty())\n                left[i]=0;\n            else\n                left[i]=st.top()+1;\n            st.push(i);\n        }\n        while(!st.empty())\n            st.pop();\n        for(int i=n-1;i>=0;i--)\n        {\n            while(!st.empty() && heights[i]<=heights[st.top()])\n                st.pop();\n            if(st.empty())\n                ryt[i]=n-1;\n            else\n                ryt[i]=st.top()-1;\n            st.push(i);\n        }\n        int ans=0;\n        for(int i=0;i<n;i++)\n        {\n            int area=heights[i]*(ryt[i]-left[i]+1);\n            ans=max(ans, area);\n        }\n        return ans;\n    }\n    int maximalRectangle(vector<vector<char>>& matrix) {\n        int m=matrix.size();\n        int n=matrix[0].size();\n        vector<vector<int>> dp(m, vector<int>(n));\n        for(int i=0;i<m;i++)\n            for(int j=0;j<n;j++)\n                dp[i][j]=matrix[i][j]-\'0\';\n        \n        for(int i=1;i<m;i++)\n            for(int j=0;j<n;j++)\n                if(dp[i][j]!=0)\n                    dp[i][j]+=dp[i-1][j];\n        int ans=0;\n        for(int i=0;i<m;i++)\n            ans=max(ans, largestRectangleArea(dp[i]));\n        return ans;\n    }\n};\n```\nPlease **UPVOTE** if it helps \u2764\uFE0F\uD83D\uDE0A\nThank You and Happy To Help You!!
['C++']