Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a grid of **n*****m** consisting** **of **O 's** and

`'s`

`'s`

(diagonals not included).**Example 1:**

Input:grid = {{X,O,X},{O,X,O},{X,X,X}}Output:3Explanation:The grid is-XOXOXOX X XSo, X with same colour are adjacent to each other vertically for horizontally (diagonals not included). So, there are 3 different groups in the given grid.

**Example 2:**

**Input: **grid = {{X,X},{X,X}}
**Output: **1
**Expanation:
**The grid is-
**X** **X**
**X X**
So, X with same colour are adjacent to each
other vertically for horizontally (diagonals
not included). So, there is only 1 group
in the given grid.

**Your Task:**

You don't need to read or print anything. Your task is to complete the function **xShape() **which takes grid as input parameter and returns the count of total X shapes.

**Expected Time Compelxity: **O(n*m)

**Expected Space Compelxity: **O(n*m)

**Constraints:**

1 ≤ n, m ≤ 100

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

X Total Shapes

...