JAVA Solution Explained in HINDI
https://youtu.be/PyJ3zsCghZ0\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote 
https://youtu.be/PyJ3zsCghZ0\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\nSubscribe link:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\nSubscribe Goal:- 400\nCurrent Subscriber:- 312\n\n# Complexity\n- Time complexity: O(m*n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maximalRectangle(char[][] matrix) {\n        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {\n            return 0;\n        }\n        \n        int n = matrix[0].length;\n        int[] curRow = new int[n];\n        int maxAns = 0; // Initialize the maximum answer\n        \n        for (int i = 0; i < matrix.length; i++) {\n            for (int j = 0; j < n; j++) {\n                if (matrix[i][j] == \'1\') {\n                    curRow[j] += 1;\n                } else {\n                    curRow[j] = 0;\n                }\n            }\n            \n            // Calculate the largest area in histogram for the current row\n            int curAns = largestAreaHistogram(curRow);\n            \n            // Update maxAns with the maximum of maxAns and curAns\n            maxAns = Math.max(maxAns, curAns);\n        }\n        \n        return maxAns;\n    }\n\n    private int largestAreaHistogram(int a[]) {\n        int n = a.length;\n        ArrayDeque<Integer> st = new ArrayDeque<>();\n        int[] leftSmall = new int[n];\n        int[] rightSmall = new int[n];\n        \n        // Calculate leftSmalls\n        for (int i = 0; i < n; i++) {\n            while (!st.isEmpty() && a[st.peek()] >= a[i]) {\n                st.pop();\n            }\n            leftSmall[i] = st.isEmpty() ? 0 : st.peek() + 1;\n            st.push(i);\n        }\n\n        // Clear the stack\n        st.clear();\n        \n        // Calculate rightSmalls\n        for (int i = n - 1; i >= 0; i--) {\n            while (!st.isEmpty() && a[st.peek()] >= a[i]) {\n                st.pop();\n            }\n            rightSmall[i] = st.isEmpty() ? n - 1 : st.peek() - 1;\n            st.push(i);\n        }\n\n        // Calculate the maximum area\n        int maxA = 0;\n        for (int i = 0; i < n; i++) {\n            maxA = Math.max(maxA, a[i] * (rightSmall[i] - leftSmall[i] + 1));\n        }\n        return maxA;\n    }\n}\n\n```
['Java']