Skip to content

Instantly share code, notes, and snippets.

@MMintzer
Created December 21, 2018 14:57
Show Gist options
  • Save MMintzer/6520585720c14ae3051c2f36bd361204 to your computer and use it in GitHub Desktop.
Save MMintzer/6520585720c14ae3051c2f36bd361204 to your computer and use it in GitHub Desktop.
river sizes prompt
// RIVER SIZES
// You are given a two-dimensiona array (matrix) of potentially unequal height and width containing only 0s and 1s.
// Each 0 represents land, and each 1 represents part of a river. A river consists of any number of adjacent 1s forming
// a river determine its size. Write a function that returns an array of the sizes of all rivers represented in the input
// matrix. Note that these sizes do not need to be in any particular order.
Sample input:
[
[1,0,0,1,0],
[1,0,1,0,0],
[0,0,1,0,1],
[1,0,1,0,1],
[1,0,1,1,0]
]
Sample output:
[1,2,2,2,5]
(1 length of 2 river,
3 length of 2 rivers,
1 length of 5 river)
@aygn2017
Copy link

how can i write in c# code

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