FastPrepVisible Profiles Count
Problems/Visible Profiles Count

Visible Profiles Count

Microsoft logoMicrosoft● MediumINTERNOA

Updated Jul 2026

QuestionFunctionExamples

Problem 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 Online Assessment questions

  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026
  • Maximum Sum of a K-StarOA · Seen Oct 2026
  • Capacity to Ship Packages Within DaysOA · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Connected GroupsVisa · OAVisa interview questions
  • 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
  • Count Connected Components in an Undirected GraphNutanix · ONSITE INTERVIEWNutanix interview questions
  • Number of ProvincesSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
  • Path Existence in an Undirected GraphByteDance · PHONE SCREENByteDance interview questions
  • Path Existence in an Undirected GraphBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] visibleProfilesCount(int connection_nodes, int connection_edges, int[] connection_from, int[] connection_to, int[] queries) {
      // write your code here
    }
}
Checking account…