Company: Ring Central_30may
Difficulty: medium
A popular social media platform provides a feature to connect people online. Connections between users are represented as an undirected graph, where each node represents a user, and edges represent connections between users. If a user is directly or indirectly connected to another user, they can view their profile. The network consists of nodes users numbered from 1 to nodes , and edges connections represented by two arrays, u and v . Each pair ( u[i] , v[i] ) indicates a connection between users u[i] and v[i] . The queries array contains a list of user IDs. For each user ID in queries, determine the total number of users whose profiles are accessible to that user. Return an array of integers where the i th value corresponds to the result for the i th query. Example nodes = 7 edges = 4 u = [1, 2, 3, 5] v = [2, 3, 4, 6] queries = [1, 3, 5, 7] The connections form the following components: Component 1: 1 - 2 - 3 - 4 (4 users) Component 2: 5 - 6 (2 users) Component 3: 7 (1 user) Query Vis