Twitter Online Assessment (OA) 2021 | Social Network
In a social media website (which is probably Twitter, if you are wondering), there are a total
n users. Each user can follow any number of other users. Let
f be a matrix of
relationship between these users, where
f[i][j] is either
i (starting from
0) is following person
0 means otherwise.
In this question, we assume that each person is following themselves, and following is
symmetrical. That is, if
i. We can then define
a "group" of people. A "group" of people are people that follow each other, either directly
or indirectly. For example, if user
0 follows user
1, and user
1 follows user
Question: How many groups are among these
f: An integer matrix representing the relationship matrix between the users.
- An integer representing the number of groups among these people.
1f = [ 2 [1, 1, 0], 3 [1, 1, 0], 4 [0, 0, 1], 5]
Explanation: There are
2 groups: User
0, 1 and user
1 are in a group
because they follow each other.
1 <= n <= 300