Skip to content

Instantly share code, notes, and snippets.

@ekampf ekampf/GalaxyCount.md
Last active Jun 5, 2018

Embed
What would you like to do?

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
You can’t perform that action at this time.