Easy || C++ Solution || Using stack || Most Optimised
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int largestRectangleArea(vector < int > & histo) {\n    stack < int > st;\n    int maxA = 0;\n    int n = histo.size();\n    for (int i = 0; i <= n; i++) {\n        while (!st.empty() && (i == n || histo[st.top()] >= histo[i])) {\n            int height = histo[st.top()];\n            st.pop();\n            int width;\n            if (st.empty())\n                width = i;\n            else\n                width = i - st.top() - 1;\n            maxA = max(maxA, width * height);\n        }\n        st.push(i);\n    }\n        return maxA;\n    }\n\n    int maximalRectangle(vector<vector<char>>& matrix) {\n        int maxArea = 0;\n        int n = matrix.size();\n        int m = matrix[0].size();\n        vector<int> height(m, 0);\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                if (matrix[i][j] == \'1\') height[j]++;\n                else height[j] = 0;\n        }\n        int area = largestRectangleArea(height);\n        maxArea = max(maxArea, area);\n         }\n        return maxArea;\n    }\n};\n```
['Stack', 'C++']