Here is the interview question prompt, presented for reference.
You're given the following multi-dimensional array matrix:
const matrix = [
[1, 1, 0, 0, 0],
[0, 1, 1, 0, 0],
[0, 1, 0, 1, 0],
[1, 0, 0, 0, 0]
];
Could you find the largest concentration of connected 1
s in the matrix? Write MostConnectedOnes(matrix: array[])
class or method that uncovers this.
A 1
is considered connected
to another 1
if it is located:
Diagonals don't count!
In the above example, the answer is 5
. Starting from position [0][0]
, we see the 1
s move to the right an index [0][1]
, down another [1][1]
, right another [1][2]
and down again [2][1]
. Here's another example:
const matrix = [
[1, 1, 0, 0],
[0, 0, 1, 0],
[0, 1, 1, 0],
[1, 0, 0, 0]
];
const mco = new MostConnectedOnes(matrix);
mco.max();
// 3
Write a method that takes a multi-dimensional array of 1
s and 0
s and returns the area
of the largest group of connected 1
s.
100000
0
or 1
n
are number of rows and m
are number of columns, then expected time and space complexity : O(nm)
You can see the full challenge with visuals at this link.
Challenges • Asked almost 7 years ago by Jake from AlgoDaily
This is the main discussion thread generated for Most Strongly Connected.