I am trying to figure out this problem from CodeFights but I don't have much experience with graph traversal so I'm struggling. One of the hints I read for this particular problem was "graph traversal" so I did a BFS but I'm not sure how to get the number of clouds.
For whatever reason with this problem and many other problems, my mind tends to go blank when it comes time to write code for it. I approached the problem as trying to find the contiguous 1's but to no avail. Can anyone help me please?
https://codefights.com/interview/pDTvSuHBgAB9dz5ik/companies/N3sScnJbzdPDQaHPj
Given a 2D grid skyMap composed of '1's (clouds) and '0's (clear sky), count the number of clouds. A cloud is surrounded by clear sky, and is formed by connecting adjacent clouds horizontally or vertically. You can assume that all four edges of the skyMap are surrounded by clear sky.
Example
skyMap = [['0', '1', '1', '0', '1'],
['0', '1', '1', '1', '1'],
['0', '0', '0', '0', '1'],
['1', '0', '0', '1', '1']]
the output should be countClouds(skyMap) = 2;
skyMap = [['0', '1', '0', '0', '1'],
['1', '1', '0', '0', '0'],
['0', '0', '1', '0', '1'],
['0', '0', '1', '1', '0'],
['1', '0', '1', '1', '0']]
the output should be countClouds(skyMap) = 5.