Java || Stack ||  O(n*m) time || Largest area in Histogram
\nclass Solution {\n    public int maximalRectangle(char[][] M) {\n    \n         int m = M.length;\n        if( m == 0) return 0;\n        int n = M[0].length;
```\nclass Solution {\n    public int maximalRectangle(char[][] M) {\n    \n         int m = M.length;\n        if( m == 0) return 0;\n        int n = M[0].length;\n        int ans  = 0;\n        int a[] = new int[n];\n        \n        for(int i = 0;i<n;i++)\n            a[i] = M[0][i]-\'0\';\n            \n        for(int i = 0;i<m;i++){\n            if( i == 0){\n                \n                ans = Math.max(ans, maximumAreaInHistogram(a));\n                continue;\n            }\n            \n            for(int j = 0; j<n;j++){\n                a[j] += M[i][j]-\'0\' ;\n                if( M[i][j] == \'0\')\n                    a[j] = 0;\n            }    \n            \n            \n            ans = Math.max(ans, maximumAreaInHistogram(a));\n            \n        }\n        \n        return ans;\n        \n        \n    }\n    \n    \n    \n   int maximumAreaInHistogram(int h[]){\n        \n        int n = h.length;\n        \n        Stack<Integer> st = new Stack();\n        \n        int l[] = new int[n];\n        int r[] = new int[n];\n        \n        \n        for(int i = 0;i<n;i++){\n            if( st.isEmpty()){\n                l[i] = -1;\n                st.push(i);\n                continue;\n            }\n            \n            while( !st.isEmpty() && h[st.peek()] >= h[i]  ){\n                st.pop();\n                \n            }\n            \n            int p = st.isEmpty() ? -1 : st.peek() ;\n            \n            l[i] = p;\n            st.push(i);\n\n        }\n        \n        st.clear();\n        \n        for(int i = n-1; i>=0; i--){\n            if( st.isEmpty()){\n                r[i] = n;\n                st.push(i);\n                continue;\n            }\n            \n            while( !st.isEmpty() && h[st.peek()] >= h[i]  ){\n                st.pop();\n                \n            }\n            \n            int p = st.isEmpty() ? n : st.peek() ;\n            \n            r[i] = p;\n            st.push(i);\n\n        }\n        \n        \n        \n        int m = 0;\n        \n        for(int i = 0;i<n;i++){\n            m = Math.max(m, h[i]*(r[i]-l[i]-1) );\n        }\n        \n        \n        return m;\n        \n    }\n    \n}\n```
['Stack', 'Java']