Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Most Strongly Connected (Main Thread)

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:

  1. above
  2. below
  3. to the left
  4. to the right of it.

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.

Constraints

  • The total number of elements in the matrix <= 100000
  • The value of the elements inside the matrix will be either 0 or 1
  • If 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 over 6 years ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Nov 30, 2017:

This is the main discussion thread generated for Most Strongly Connected.