Visible Profiles Count
A popular social media platform provides a feature to connect people online. Connections are represented as an undirected graph where a user can see the profiles of those they are connected to.
There are connection_nodes users numbered 1 to connection_nodes, and connection_edges connections where the pth pair connects nodes connection_from[p] and connection_to[p]. The queries array contains node numbers. Find the number of users whose profiles are visible to query[p]. Report an array of integers where the pth value is the answer to the pth query.
Complete the function visibleProfilesCount in the editor.
visibleProfilesCount has the following parameters:
connection_nodes: an integer, the number of usersconnection_edges: an integer, the number of connectionsconnection_from[p]: an array of integers, the starting nodes of each connectionconnection_to[p]: an array of integers, the ending nodes of each connectionqueries: an array of integers, the node numbers to query
Returns
int[]: an array of integers where the pth value is the number of visible profiles for the pth query
1Example 1

For each query, the number of visible profiles is calculated as follows:
- Query 1: Visible Profiles are [1, 2, 3, 4]. Number of Visible Profiles is 4.
- Query 3: Visible Profiles are [1, 2, 3, 4]. Number of Visible Profiles is 4.
- Query 5: Visible Profiles are [5, 6]. Number of Visible Profiles is 2.
- Query 7: Visible Profiles are []. Number of Visible Profiles is 1 (the user can see their own profile).
Therefore, the function returns [4, 4, 2, 1].
Constraints
Limits and guarantees your solution can rely on.
🐳