GeeksforGeeks » Interview Questions

Find the number of blocks

(6 posts)
  1. guru
    guest
    Posted 11 months ago #

    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 2

    3
    3

    4

    1 2 3
    4 5 6
    7 8 9
    has 9 blocks

    1 1 1
    1 1 3
    4 4 5
    has 4 blocks,
    1 1 1
    1 1

    3

    5

    4 4

  2. Nanu
    guest
    Posted 11 months ago #

    Do we have the range of numbers known?

  3. Sambasiva
    Member
    Posted 11 months ago #

  4. WgpShashank
    guest
    Posted 11 months ago #

    @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

  5. rajcools
    Member
    Posted 11 months ago #

    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???

  6. Sambasiva
    Member
    Posted 11 months ago #

    @Shashank, corrected


Reply

You must log in to post.

RSS feed for this topic