Dsa
Graphs Bfs
Easy
Social Network Connectivity
You are given a list of friendships represented as pairs of integers. Each integer represents a user. Your task is to determine if two users are connected through their friendships directly or indirectly. Implement a function that takes a list of friendships and two users and returns 'Yes' if they are connected and 'No' otherwise.
Input format:
N F
A1 B1
A2 B2
...
AF BF
U1 U2
Where N is the number of users (1 <= N <= 100), F is the number of friendships (0 <= F <= N*(N-1)/2), and the friendships are listed below. U1 and U2 are the users to check for connectivity.
Output format:
Print 'Yes' or 'No'.
Example:
Input:
4 3
1 2
2 3
1 4
2 4
1 3
Output:
Yes
Key concepts
graphsbfsconnectivity
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now