Google | Onsite | Zero Sub-matrices | SWE | Round-4 (Technical)
Anonymous User
2289

Given a 2-D matrix containing only 1's or 0's. Find the number of sub-matrices containing only 0's.

For eg.,

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

Ans => 16
[[0]] => 7
[[0,0]] => 3
[[0],[0]] => 3
[[0,0,0]] => 1
[[0],[0],[0]] => 1
[[0,0],[0,0]] => 1

7 + 3 + 3 + 1 + 1 + 1= 16

Please do share your solutions to this problem.
I am not sure but the interviewer hinted towards some O(m * n) algorithm.

Comments (17)