Question: Given a 2 d grid map of ' 1 ' s ( wood ) and ' 0 ' s ( water ) , count the

Given a 2d grid map of '1's (wood) and '0's (water), count the boats in the sea.
A boat is surrounded by water and is formed by connecting adjacent wood horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
A single wood surrounded by water is also considered as a boat. Find the number of boats in the sea.
Let R be the number of rows and C be the number of columns in the grid.
Input format:
The first line consists of 2 integers R and C.
Followed by a matrix of size R x C.
Output format:
Print the number of boats in a sea.
Constraints
0R100
0C100
Examples
Input:
44
1011
0000
1100
1101
Output:
4
 Given a 2d grid map of '1's (wood) and '0's (water),

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!