Write python code to find the submatrix. Thank you in Advance.   You are given a 2D matrix that is filled with 1's in almost all the cells. However, there may be at most one rectangular submatrix that is filled with 0s. Implement an algorithm to return the size of the submatrix, in terms of width and height.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 24PE
icon
Related questions
Question

Write python code to find the submatrix.

Thank you in Advance.

 

You are given a 2D matrix that is filled with 1's in almost all the cells. However, there may be at most one rectangular submatrix that is filled with 0s. Implement an algorithm to return the size of the submatrix, in terms of width and height.

Examples:

Input:

[[1,1,1,1,1,1,1],

[1,1,1,1,1,1],

[1,1,0,0,0,1],

[1,1,0,0,0,1],

11,1,1,1,1,1]]

Output: [3,2] (Because the width of the sumbmarix 3, and highets 2

Input:

[[1,1,1,1],

[1,1,1,1],

[1,1,1,1]]

Output: [0,0] (Because the there is no submatrix that contains 0s)

Input:

[[1,1,1,1],

[1,1,0,1]

[1,1,1,1]]

Output: [1,1] (Because the width of the submatrix of 0s is 1, and height is 1)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning