Easiest Java Solution|| Beats 100%
\n Describe your approach to solving the problem. \nWe can solve this question using the "Largest Rectangle in Histogram" question approach. consider every row 
\n<!-- Describe your approach to solving the problem. -->\nWe can solve this question using the "Largest Rectangle in Histogram" question approach. consider every row as a histogram and for every row find the max rectangle area. \n\nYou can check the histogram approach [here](https://leetcode.com/problems/largest-rectangle-in-histogram/solutions/3845893/best-simple-java-solution-beats-85/).\n\nAlso, if the current row has an element with 0 value, then the height will be 0. for the rest where matrix[i][j] == 0, just add the previous value + 1, \n\n# Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\n\n    public static int histogram(int[] heights){\n         int n = heights.length;\n\n        ArrayDeque<Integer> st1 = new ArrayDeque<>();\n        ArrayDeque<Integer> st2 = new ArrayDeque<>();\n\n        int left[] = new int[n];\n        int right[] = new int[n];\n\n        //previous smaller element\n        for(int i = 0; i < n; i++){\n\n            int num = heights[i] ;\n\n            while(!st1.isEmpty() && heights[st1.peek()] > num)\n                st1.pop();\n\n            if(st1.isEmpty())\n                left[i] = -1;\n            else \n                left[i] = st1.peek();\n\n            st1.push(i);            \n\n        }\n    \n\n        //next greater element\n        for(int i = n-1; i >= 0; i--){\n\n            int num = heights[i];\n\n            while(!st2.isEmpty() && heights[st2.peek()] >= num)\n                st2.pop();\n\n            if(st2.isEmpty())\n                right[i] = n;\n            else \n                right[i] = st2.peek();\n\n            st2.push(i);            \n\n        }\n\n        int max = Integer.MIN_VALUE;\n        for(int i = 0; i < n; i++){\n\n            int sum = (right[i] - left[i] - 1) * (heights[i]);\n            max = Math.max(max, sum); \n\n        }\n\n        System.out.println("Max"+ max);\n        return max;\n    }\n\n    public int maximalRectangle(char[][] matrix) {\n        \n        int n = matrix.length;\n        int m = matrix[0].length;\n        int[] currRow = new int[matrix[0].length];\n        int max = 0;\n\n        for(int i = 0; i < n; i++){\n\n            for(int j = 0; j < m; j++){\n\n                if(matrix[i][j] == \'1\')\n                    currRow[j]++;\n                else \n                    currRow[j] = 0;    \n            }\n\n            int currMax = histogram(currRow);\n            max = Math.max(max, currMax);\n\n        }\n\n        return max;\n        \n    }\n}\n```
['Dynamic Programming', 'Stack', 'Monotonic Stack', 'Java']