Back to problems

Connected Groups

Algorithm · Visa · Easy

You are given an $$N \times N$$ character matrix related that encodes pairwise connections between N entities. related[i][j] == '1' means entity i is directly connected to entity j. related[i][j] == '0' means no direct connection exists between them. The relationship is undirected, so related[i][j] always equals related[j][i]. Connectivity is transitive: if A is connected to B and B is connected to C, then A, B, and C all belong to the same group. Your task is to return the…

Checking your access…