Skip to content

Instantly share code, notes, and snippets.

@nhuntwalker
Created December 7, 2017 19:58
Show Gist options
  • Save nhuntwalker/5f2832f58fefae4367344488765b53e8 to your computer and use it in GitHub Desktop.
Save nhuntwalker/5f2832f58fefae4367344488765b53e8 to your computer and use it in GitHub Desktop.
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