Created
December 7, 2017 19:58
-
-
Save nhuntwalker/5f2832f58fefae4367344488765b53e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You're given a grid of 1's and 0's. | |
A cluster of 1's corresponds with every 1 that has 1 as a neighbor to the left, right, up, or down. | |
Return an array of the size of each cluster of 1's in the grid. | |
Example: | |
input = [ | |
[1,1,1,0,0,0,0], | |
[1,1,0,0,0,0,1], | |
[0,0,0,0,1,0,1], | |
[0,1,1,0,0,0,0], | |
[0,0,0,1,1,0,1], | |
[0,0,0,1,1,0,1] | |
] | |
output = [5, 2, 1, 2, 4, 2] # in any order |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment