Given a 2d grid of '1's (space clusters with stars) and '0's (dark space clusters without any stars), count the number of galaxies on the grid. An Galaxy is a group a space clusters containing stars, surrounded by dark clusters (no starts) and connected horizontally or vertically.
Examples:
Input:
11000
11000
00000
00011
Number of Galaxies: 2
Input:
11000
11000
00100
00011
Number of Galaxies: 3
Input:
11110
11010
11000
00000
Number of Galaxies: 1
Implement a function that gets an 2d grid as input and returns the number of galaxies:
var numGalaxies = function(grid) {
};
Write a detailed description of the approach you used to solve the problem. Is it the optimal solution? Could you write a better alternative if you had more time?
Write a simple HTML interface with a dynamic NxN grid where the user can toggle the different cells to be Star\Dark clusters and see the number of galaxies in the grid.
Preferrably use React\Angular\Vue\Backbone or any other application framework to properly write your single-page app's code.