FastPrepVisible Profiles Count
Problems/Visible Profiles Count

Visible Profiles Count

IBM logoIBM● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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.

Function

visibleProfilesCount(connection_nodes: int, connection_edges: int, connection_from: int[], connection_to: int[], queries: int[]) → int[]

Complete the function visibleProfilesCount in the editor.

visibleProfilesCount has the following parameters:

  1. connection_nodes: an integer, the number of users
  2. connection_edges: an integer, the number of connections
  3. connection_from[p]: an array of integers, the starting nodes of each connection
  4. connection_to[p]: an array of integers, the ending nodes of each connection
  5. queries: 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

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]
Example 1 illustration

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

  • 🐳

More IBM interview questions

  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Alternate Odd and Even Numbers with Two GoroutinesPHONE SCREEN · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026
  • Merge Two Sorted ListsPHONE SCREEN · Seen Oct 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Oct 2026
  • Tree Pythagorean TriplesOA · Seen Oct 2026

Similar questions at other companies

  • Connected GroupsVisa · OAVisa interview questions
  • Visible Profiles CountMicrosoft · OAMicrosoft interview questions
  • Get Node To RemoveSalesforce · OASalesforce interview questions
  • Malware SpreadFlexport · OAFlexport interview questions
  • Team TournamentNutanix · OANutanix interview questions
  • Path Existence in an Undirected GraphByteDance · PHONE SCREENByteDance interview questions
  • Path Existence in an Undirected GraphBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Record Linkage Part 3 - Full Connected ComponentStripe · PHONE SCREENStripe interview questions
  • Evaluate DivisionApple · PHONE SCREENApple interview questions
  • Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions

IBM interview experiences

  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM 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…