A simple C++ Approach with explanation
This is a mixture of two problems that is\n1. Finding the largest rectangle in an Histogram.\n2. Then finding the answer for the particular problem\n\nI hereby 
This is a mixture of two problems that is\n1. Finding the largest rectangle in an Histogram.\n2. Then finding the answer for the particular problem\n\nI hereby assume that u know how to find the largest Rectangle in a Histogram,if not check this out\nhttps://leetcode.com/problems/largest-rectangle-in-histogram/\nSolve  it first before jumping to it as the intuition behind that problem is the base for this and those who have solve that here is the explanation..\n\nThe function find answer is the snippet which simply finds the maximum area rectangle in an histogram but before that the main function requires some preprocessing..\nIf given the Input\n1 0 1 0 0 \n1 0 1 1 1\n1 1 1 1 1\n1 0 0 1 0\n\n**We can assume each row as potential input for histogram but for every row we have to take the cummulative sum with the above row inorder to get how many 1\'s are there in the above row**\n\nOnce u get the above where each cummulative sum vector is an input for the function **find_ans** which calculates largest are rectangle we can extend it to 2D as well,Once u get the above then it is down hill from there..\n\n```\nclass Solution {\npublic:\n    int find_ans(vector<int>& h)\n    {\n        h.push_back(0);\n        int n = h.size();\n        stack<int> s;\n        int sum = 0;\n        for(int i=0;i<n;i++)\n        {\n            while(!s.empty() && h[i] < h[s.top()])\n            {\n                int idx = s.top();\n                s.pop();\n                int l = s.empty() ? 0 : s.top() + 1;\n                sum = max(sum,h[idx]*(i-l));\n            }\n            s.push(i);\n        }\n        return sum;\n    }\n    int maximalRectangle(vector<vector<char>>& matrix) {\n        if(matrix.empty())\n            return 0;\n        int n = matrix.size();\n        int m = matrix[0].size();\n        int max_ans = 0;\n        vector<int> h(m,0);\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n                if(matrix[i][j] == \'0\')\n                    h[j] = 0;\n                else\n                    h[j]++;\n            max_ans = max(max_ans,find_ans(h));\n        }\n        return max_ans;\n    }\n};\n```\n\n**Upvotes are appreciated**
[]