GeeksforGeeks » Interview Questions
Find the number of blocks
(6 posts)-
Given a matrix, you need to find the number of blocks in it. A block has the same numbers.
EG:
1 1 3
1 2 3
2 2 4
has 4 blocks namely,
1 1
1
2
2 23
34
1 2 3
4 5 6
7 8 9
has 9 blocks1 1 1
1 1 3
4 4 5
has 4 blocks,
1 1 1
1 13
5
4 4
-
Do we have the range of numbers known?
-
@samabasiva ur algo will fail in case of
1 1 3
1 2 3
2 2 4& i am sure it will fail, for many cases i think BFS will work here
-
i dont think even BFS will be full proof here. as we r given matrix we will need to check all surrounding elements.
for i,j check i,j+1 ; i+1,j-1;i+1,j;i+1,j+1[i am taking into assumtion that we start from zero , special cases can be handled for 1st row,last row,1st column,last column] and then subsequently for others untill we find some other element
what do u say shashank about this???
-
@Shashank, corrected
Reply
You must log in to post.