{"id":"b13fc41d-434d-40ad-bcf6-e2e6b90cf036","name":"Maximal Rectangle","description":"1. Given a rows x cols binary matrix filled with 0's and 1's.\r\n2. Find the largest rectangle containing only 1's and return its area.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= row, cols &lt;= 200\r\n2. matrix[i][j] is 0 or 1.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n\nint maximalRectangle(vector<vector<int>> arr) {\n //write your code here\n}\n\n\n\n\n\nint main(int argc, char** argv)\n{\n int n, m;\n cin >> n >> m;\n vector<vector<int>> bmat(n, vector<int>(m, -1));\n\n for (int i = 0; i < n; i++) {\n string str;\n cin >> str;\n for (int j = 0; j < m; j++) {\n bmat[i][j] = str[j] == '0' ? 0 : 1;\n }\n }\n\n cout << maximalRectangle(bmat);\n\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int maximalRectangle(int[][] ar) { \r\n return 0;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int row = Integer.parseInt(read.readLine());\r\n int col = Integer.parseInt(read.readLine());\r\n \r\n int bmat[][] = new int[row][col];\r\n\r\n for(int i=0;i<row;i++){\r\n String s = read.readLine();\r\n for(int j=0;j<col;j++){\r\n bmat[i][j] = s.charAt(j)-''0'';\r\n }\r\n }\r\n\r\n int result = maximalRectangle(bmat);\r\n System.out.println(result);\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"2\r\n5\r\n10100\r\n10111","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/bgWt2qtFhbQ","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"029b646d-9b67-48ca-a6fe-50777a88232b","name":"Maximal Rectangle","slug":"maximal-rectangle","type":1}],"next":{"id":"6f9951ce-6bae-4aa7-b225-2034fba37a58","name":"Maximal Rectangle Hard MCQ","type":0,"slug":"maximal-rectangle-hard-mcq"},"prev":{"id":"e5908b25-18dd-4da5-a163-f3eedb10f5b7","name":"Largest Area Histogram 2","type":3,"slug":"largest-area-histogram-2"}}}

Maximal Rectangle

1. Given a rows x cols binary matrix filled with 0's and 1's. 2. Find the largest rectangle containing only 1's and return its area.

{"id":"b13fc41d-434d-40ad-bcf6-e2e6b90cf036","name":"Maximal Rectangle","description":"1. Given a rows x cols binary matrix filled with 0's and 1's.\r\n2. Find the largest rectangle containing only 1's and return its area.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= row, cols &lt;= 200\r\n2. matrix[i][j] is 0 or 1.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n\nint maximalRectangle(vector<vector<int>> arr) {\n //write your code here\n}\n\n\n\n\n\nint main(int argc, char** argv)\n{\n int n, m;\n cin >> n >> m;\n vector<vector<int>> bmat(n, vector<int>(m, -1));\n\n for (int i = 0; i < n; i++) {\n string str;\n cin >> str;\n for (int j = 0; j < m; j++) {\n bmat[i][j] = str[j] == '0' ? 0 : 1;\n }\n }\n\n cout << maximalRectangle(bmat);\n\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int maximalRectangle(int[][] ar) { \r\n return 0;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int row = Integer.parseInt(read.readLine());\r\n int col = Integer.parseInt(read.readLine());\r\n \r\n int bmat[][] = new int[row][col];\r\n\r\n for(int i=0;i<row;i++){\r\n String s = read.readLine();\r\n for(int j=0;j<col;j++){\r\n bmat[i][j] = s.charAt(j)-''0'';\r\n }\r\n }\r\n\r\n int result = maximalRectangle(bmat);\r\n System.out.println(result);\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"2\r\n5\r\n10100\r\n10111","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/bgWt2qtFhbQ","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"029b646d-9b67-48ca-a6fe-50777a88232b","name":"Maximal Rectangle","slug":"maximal-rectangle","type":1}],"next":{"id":"6f9951ce-6bae-4aa7-b225-2034fba37a58","name":"Maximal Rectangle Hard MCQ","type":0,"slug":"maximal-rectangle-hard-mcq"},"prev":{"id":"e5908b25-18dd-4da5-a163-f3eedb10f5b7","name":"Largest Area Histogram 2","type":3,"slug":"largest-area-histogram-2"}}}
plane

Editor


Loading...

Maximal Rectangle

hard

1. Given a rows x cols binary matrix filled with 0's and 1's. 2. Find the largest rectangle containing only 1's and return its area.

Constraints

1. 1 <= row, cols <= 200 2. matrix[i][j] is 0 or 1.

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

2 5 10100 10111

Sample Output

3

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode