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 1s 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 1s 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 1s and 0s and returns the area of the largest group of connected 1s.
1000000 or 1n 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 8 years ago by Team AlgoDaily
This is the main discussion thread generated for Most Strongly Connected.