the note will be written in c# code. Q 2: River Lengths It gives you two potentially unequal height and width, containin

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

the note will be written in c# code. Q 2: River Lengths It gives you two potentially unequal height and width, containin

Post by answerhappygod »

the note will be written in c# code.
Q 2: River Lengths
It gives you two potentially unequal height and width, containing
only 0's and 1's.
A dimensional array (matrix) is given. Each 0 represents land and
each 1 represents a section of a river.
A river is any number of horizontally or vertically adjacent (but
not diagonally adjacent)
It consists of 1. The number of adjacent 1s that make up a river
determines its size.
Remember that a river can bend. In other words, a straight vertical
line or a straight horizontal line.
it doesn't have to be; For example, it can be L-shaped.
Write a method that returns an array of the sizes of all rivers
represented in the input matrix.
The dimensions do not have to be in any particular order.
Example Input
matrix = [
[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, 5] // Numbers can be sorted differently.
public static List<int> RiverLengths(int[,] matrix) {
// Write your code here.
return new List<int>();
}
The 5 different rivers on the matrix are shown in different
colors.
The length of 3 rivers is 2 units, the length of 1 river is 1 unit,
other
The length of the river is 5 units.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply