Skip to content

Instantly share code, notes, and snippets.

@ekampf
Last active June 5, 2018 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekampf/fc9328524db5c3444d03d5a61b2e9fe1 to your computer and use it in GitHub Desktop.
Save ekampf/fc9328524db5c3444d03d5a61b2e9fe1 to your computer and use it in GitHub Desktop.

Galaxies Count

Problem Description

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

Task #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?

Task #2:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment