FastPrepConnected Groups
Problems/Connected Groups

Connected Groups

Visa logoVisa● EasyFULLTIMEOA
QuestionFunctionExamples

Problem statement

Source note: The source supplies the binary related matrix, transitive-connectivity rule, and required component count, but omits the callable signature and numeric bounds. The judged core task matches the visible source at about 98%.

Given an N by N symmetric binary matrix related, treat each index as one member. When related[i][j] == 1, members i and j are directly related.

Membership is transitive: members connected through any chain of direct relationships belong to the same group. Every member belongs to exactly one group, including an isolated member.

Return the number of connected groups.

Function

countConnectedGroups(related: int[][]) → int

Examples

Example 1

related = [[1,1,0],[1,1,0],[0,0,1]]return = 2

Members 0 and 1 form one group, while member 2 is isolated and forms the second group.

Example 2

related = [[1,0,0,0],[0,1,1,0],[0,1,1,1],[0,0,1,1]]return = 2

Member 0 is one group. Members 1, 2, and 3 form the other because 1 reaches 3 through 2.

More Visa problems

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • House RobberPHONE SCREEN · Seen Nov 2026
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int countConnectedGroups(int[][] related) {
        // Write your code here.
    }
}
Checking account…