FastPrepNumber of Provinces
Problems/Number of Provinces

Number of Provinces

SambaNova Systems logoSambaNova Systems● MediumNEW GRADPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand SambaNova phone interview report dated June 9, 2022 describes the friend-circle problem using a list-of-strings adjacency matrix. This equivalent integer-matrix interface preserves the connected-component task.

You are given an n x n matrix isConnected. If isConnected[i][j] = 1, person i and person j are direct friends.

A friend circle is a group of directly or indirectly connected people with no friendship to anyone outside the group.

Return the total number of friend circles.

Function

findCircleNum(isConnected: int[][]) → int

Examples

Example 1

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

People 0 and 1 form one friend circle, while person 2 forms another.

Example 2

isConnected = [[1,0,0],[0,1,0],[0,0,1]]return = 3

No two distinct people are friends, so every person is their own friend circle.

Example 3

isConnected = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]]return = 1

The direct friendships form one transitive chain containing all four people.

Constraints

  • 1 ≤ n ≤ 200
  • isConnected.length = n
  • isConnected[i].length = n
  • isConnected[i][j] is 0 or 1.
  • isConnected[i][i] = 1
  • isConnected[i][j] = isConnected[j][i]

More SambaNova Systems Phone Screen questions

  • Deterministic Zigzag SortPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Minimum Window SubstringPHONE SCREEN · Seen Jun 2022
  • Merge Three Sorted ArraysPHONE SCREEN · Seen Jun 2022
  • Task Scheduler with CooldownPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Point Inside a TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Parse Variable, Expression, and Application TreesPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
  • Decode StringPHONE SCREEN · Seen Mar 2022
  • Insert, Delete, and Get Random in Constant TimePHONE SCREEN · Seen Mar 2022
  • Ugly NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2021
  • Diagonal TraversePHONE SCREEN · Seen Nov 2020

Similar questions at other companies

  • Evaluate DivisionApple · PHONE SCREENApple interview questions
  • Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Count Connected Point ClustersGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Count the Number of Complete ComponentsAmazon · PHONE SCREEN
  • Path Existence in an Undirected GraphByteDance · PHONE SCREENByteDance interview questions
  • Visible Profiles CountMicrosoft · OAMicrosoft interview questions
  • Count Connected Components in an Undirected GraphNutanix · ONSITE INTERVIEWNutanix interview questions
  • Connected GroupsVisa · OAVisa interview questions
  • Path Existence in an Undirected GraphBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Record Linkage Part 3 - Full Connected ComponentStripe · PHONE SCREENStripe interview questions
All SambaNova Systems interview questionsSee SambaNova Systems hiring insights
Saved
class Solution {
    public int findCircleNum(int[][] isConnected) {
        // write your code here
    }
}
Checking account…