Detailed explanation (code + video) with best time complexity
Please refer this video for detailed explanation - \n[https://www.youtube.com/watch?v=Q39oYu4p9gY]\n\n\n\nclass Solution {\n    public int maximalRectangle(char
Please refer this video for detailed explanation - \n[https://www.youtube.com/watch?v=Q39oYu4p9gY]\n\n\n```\nclass Solution {\n    public int maximalRectangle(char[][] matrix) {\n        if(matrix.length == 0)\n            return 0;\n        int max = 0;\n        int[] height = new int[matrix[0].length];\n        for(int i=0; i<matrix.length; i++){\n            for(int j=0; j<matrix[0].length; j++){\n                if(matrix[i][j] == \'0\'){\n                    height[j] = 0;\n                } else {\n                    height[j]+=1;\n                }\n            }\n            max = Math.max(max, findTheArea(height));\n        }\n        return max;\n    }\n    \n    public int findTheArea(int[] h){\n        int max = 0;\n        Stack<Integer> stack = new Stack<>();\n        stack.add(0);\n        for(int i=1; i<h.length; i++){\n            int curr = h[i];\n            if(stack.isEmpty() || curr >= h[stack.peek()]){\n                stack.add(i);\n            } else {\n                while(!stack.isEmpty() && curr < h[stack.peek()]){\n                    int temp = h[stack.pop()];\n                    if(stack.isEmpty()){\n                        max = Math.max(max, temp*i);\n                    } else {\n                        max = Math.max(max, temp*(i-stack.peek()-1));\n                    }\n                }\n                stack.add(i);\n            }\n        }\n        \n        if(!stack.isEmpty()){\n             while(!stack.isEmpty()){\n                    int i = h.length;\n                    int temp = h[stack.pop()];\n                    if(stack.isEmpty()){\n                        max = Math.max(max, temp*i);\n                    } else {\n                        max = Math.max(max, temp*(i-stack.peek()-1));\n                    }\n                }\n        }\n        return max;\n    }\n}\n```
[]