FastPrepConnected Groups
Problems/Connected Groups

Connected Groups

Fivetran logoFivetran● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report does not give a concrete matrix example, a function signature, or input limits. We chose those. Our version is about 90% the same as the reported question.

You are given a square binary matrix related. Each row and column represents one person at the same party.

  • related[i][j] == 1 means that person i and person j have a direct connection.
  • related[i][j] == 0 means that they do not have a direct connection.

Connections are transitive. If person a is connected to person b, and person b is connected to person c, then all three people belong to the same group.

Return the number of distinct groups. If related is empty, return 0.

Function

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

Examples

Example 1

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

Person 0 is directly connected to person 1, and person 1 is directly connected to person 2. Transitivity places all three people in one group.

Example 2

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

Person 0 forms one group. Persons 1 and 2 form the other group.

Example 3

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

Persons 0 and 2 form one group, while persons 1 and 3 form the other. Group members do not need consecutive indices.

Constraints

  • Let n = related.length.
  • 0 <= n <= 1000.
  • related has exactly n rows, and every row has exactly n entries.
  • Every entry in related is either 0 or 1.
  • related[i][i] == 1 for every valid index i.
  • related[i][j] == related[j][i] for all valid indices i and j.

More Fivetran interview questions

  • Unique Near-Equal Target-Sum PairsONSITE INTERVIEW · Seen Jun 2024
  • Reschedule Meetings for Maximum Free TimeOA · Seen Nov 2026
  • Execute In-Memory SQL Storage OperationsPHONE SCREEN · Seen Sep 2026
  • Aladdin and the Magic CarpetPHONE SCREEN · Seen Jun 2025
  • Minimum Fuel Car AlignmentPHONE SCREEN · Seen Jun 2023

Similar questions at other companies

  • Largest Island After One Land ConversionGoogle · ONSITE INTERVIEWGoogle interview questions
  • Making a Large IslandMeta · ONSITE INTERVIEWMeta interview questions
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Count Islands in a GridDoorDash · PHONE SCREENDoorDash interview questions
  • Connected GroupsVisa · OAVisa interview questions
  • Number of IslandsFleetx · ONSITE INTERVIEW
  • Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Evaluate DivisionPlaud · ONSITE INTERVIEW
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions

Interview reports that mention this question

  • Fivetran SDE 2 Java and Concurrency Interviews: 1 Experience

Fivetran interview experiences

  • Fivetran Staff SRE Hiring Manager Interview: 1 Experience
  • Fivetran Software Engineer HackerRank and Java: 1 Experience
  • Fivetran Senior SRE Interview Process: 1 Experience
  • Fivetran Software Engineer HashMap and Design: 1 Experience
  • Fivetran SDE-2 Coding and Parking Lot Design: 1 Experience
All Fivetran interview questionsSee Fivetran hiring insights
Saved
class Solution {
    public int countConnectedGroups(int[][] related) {
        // Write your code here.
    }
}
Checking account…