Black Shapes


Given N x M character matrix A of O's and X's, where O = white, X = black.

Return the number of black shapes. A black shape consists of one or more adjacent X's (diagonals not included)



Input Format:

    The First and only argument is a N x M character matrix.

Output Format:

    Return a single integer denoting number of black shapes.

Constraints:

    1 <= N,M <= 1000
    A[i][j] = 'X' or 'O'

Example:

Input 1:
    A = [ OOOXOOO
          OOXXOXO
          OXOOOXO  ]
Output 1:
    3
Explanation:
    3 shapes are  :
    (i)    X
         X X
    (ii)
          X
    (iii)
          X
          X

Note: we are looking for connected shapes here.

XXX
XXX
XXX

is just one single connected black shape.

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Black Shapes on Interview Code Editor
Sign Up
to access hints and editorial solutions for Black Shapes
Asked In:

Discussion


Loading...
Click here to start solving coding interview questions