Find the Number of Continents in a 2D Array

You are given a two dimensional array containing arrays of integers as an argument. Each integer in the inner arrays will either be a 1 or a 0, with 1's representing a landmass. Continents are formed by one or more 1's next to above or below each other (not diagonally). Return the number of continents that are formed in the 2D array.

The 2D array's inner arrays will always be equal in length.

Requirements

  • Must return a single integer

Example #1

solve([
  [0, 1, 1, 0, 0, 1],
  [0, 1, 1, 0, 0, 1],
  [0, 0, 0, 0, 0, 0],
  [1, 1, 1, 0, 0, 1],
  [0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0]
])
> 5
  1. The first and second inner arrays have a group of four 1's, so our count is at 1.
  2. The first and second inner arrays have a group of two 1's in the sixth column, our count is at 2.
  3. The fourth inner array has a group of three 1's next to each other, our count is at 3.
  4. The fourth inner array has a single 1 in the sixth column, our count is at 4.
  5. The last inner array has a single 1 in the fifth column, our final count is at 5, which is what we will return.