{"id":"72a42ea5-983a-4af8-b5d9-87942991859d","name":"Largest Square Sub-matrix With All 1's","description":"1. You are given a matrix of 0's and 1's.\r\n2. You have to find the maximum size square sub-matrix with all 1's.","inputFormat":"A number N, which represents number of rows in matrix\r\nA number M, which represents number of columns in matrix\r\narr1\r\narr2...N*M numbers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N,M &lt;= 100\r\n0&lt;= arr[i][j] &lt;= 1","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int[][] arr) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint m =scn.nextInt();\r\n\t\tint[][] arr = new int[n][m];\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tfor(int j = 0 ; j < m; j++){\r\n\t\t\t\tarr[i][j] = scn.nextInt();\r\n\t\t\t}\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5 6\r\n0 1 0 1 0 1 \r\n1 0 1 0 1 0 \r\n0 1 1 1 1 0 \r\n0 0 1 1 1 0 \r\n1 1 1 1 1 1","sampleOutput":"3\r\n","questionVideo":"","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"686ba90f-0d2a-461e-9ea1-2b5b4321a1cb","name":"Largest Square Sub-matrix With All 1's","slug":"largest-square-sub-matrix-with-all-1-s","type":1}],"next":{"id":"65436969-8531-4a30-b5ff-dbf2ab2c8960","name":"Highway Billboard","type":1,"slug":"highway-billboard"},"prev":{"id":"4ca253c0-79d6-498c-bf0b-fad988f6bd1d","name":"Min MAx Value Expression MCQ","type":0,"slug":"min-max-value-expression-mcq"}}}

Largest Square Sub-matrix With All 1's

1. You are given a matrix of 0's and 1's. 2. You have to find the maximum size square sub-matrix with all 1's.

{"id":"72a42ea5-983a-4af8-b5d9-87942991859d","name":"Largest Square Sub-matrix With All 1's","description":"1. You are given a matrix of 0's and 1's.\r\n2. You have to find the maximum size square sub-matrix with all 1's.","inputFormat":"A number N, which represents number of rows in matrix\r\nA number M, which represents number of columns in matrix\r\narr1\r\narr2...N*M numbers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N,M &lt;= 100\r\n0&lt;= arr[i][j] &lt;= 1","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int[][] arr) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint m =scn.nextInt();\r\n\t\tint[][] arr = new int[n][m];\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tfor(int j = 0 ; j < m; j++){\r\n\t\t\t\tarr[i][j] = scn.nextInt();\r\n\t\t\t}\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5 6\r\n0 1 0 1 0 1 \r\n1 0 1 0 1 0 \r\n0 1 1 1 1 0 \r\n0 0 1 1 1 0 \r\n1 1 1 1 1 1","sampleOutput":"3\r\n","questionVideo":"","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"686ba90f-0d2a-461e-9ea1-2b5b4321a1cb","name":"Largest Square Sub-matrix With All 1's","slug":"largest-square-sub-matrix-with-all-1-s","type":1}],"next":{"id":"65436969-8531-4a30-b5ff-dbf2ab2c8960","name":"Highway Billboard","type":1,"slug":"highway-billboard"},"prev":{"id":"4ca253c0-79d6-498c-bf0b-fad988f6bd1d","name":"Min MAx Value Expression MCQ","type":0,"slug":"min-max-value-expression-mcq"}}}
plane

Editor


Loading...

Largest Square Sub-matrix With All 1's

medium

1. You are given a matrix of 0's and 1's. 2. You have to find the maximum size square sub-matrix with all 1's.

Constraints

1 <= N,M <= 100 0<= arr[i][j] <= 1

Format

Input

A number N, which represents number of rows in matrix A number M, which represents number of columns in matrix arr1 arr2...N*M numbers

Output

Check the sample output and question video.

Example

Sample Input

5 6 0 1 0 1 0 1 1 0 1 0 1 0 0 1 1 1 1 0 0 0 1 1 1 0 1 1 1 1 1 1

Sample Output

3

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode