Problem · Graph
Visible Profiles Count
Learn this problemProblem statement
A social media platform represents user connections as an undirected graph. Each node is a user, and each edge is a connection between two users.
If two users are directly or indirectly connected, they can view each other's profiles. A user can also view their own profile.
The network contains connection_nodes users numbered from 1 to connection_nodes and connection_edges connections. The ith connection joins connection_from[i] and connection_to[i].
For each user ID in queries, return the total number of profiles accessible to that user.
Function
visibleProfilesCount(connection_nodes: int, connection_edges: int, connection_from: int[], connection_to: int[], queries: int[]) → int[]Examples
Example 1
connection_nodes = 7connection_edges = 4connection_from = [1,2,3,5]connection_to = [2,3,4,6]queries = [1,3,5,7]return = [4,4,2,1]Users 1, 2, 3, and 4 form one connected component, so queries 1 and 3 each return 4. Users 5 and 6 form a component of size 2. User 7 is isolated but can view their own profile, so the final result is 1.
More Microsoft problems
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026
- Maximum Strength of Every NeuronOA · Seen Jul 2026
- Neural Network Subnetwork StrengthOA · Seen Jul 2026
- XOR MultiplicationOA · Seen Jul 2026