Number of Provinces
Updated
Problem statement
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[][]) → intExamples
Example 1
isConnected = [[1,1,0],[1,1,0],[0,0,1]]return = 2People 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 = 3No 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 = 1The direct friendships form one transitive chain containing all four people.
Constraints
1 ≤ n ≤ 200isConnected.length = nisConnected[i].length = nisConnected[i][j]is0or1.isConnected[i][i] = 1isConnected[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