FastPrepViewable Profiles by User
Problems/Viewable Profiles by User

Viewable Profiles by User

Salesforce logoSalesforceFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

A social media platform represents user connections as an undirected graph. Users are numbered from 1 to nodes. If one user is directly or indirectly connected to another user, they can view that user's profile.

You are given two arrays u and v, where u[i] and v[i] are connected. You are also given an array queries.

For each queried user, return the number of profiles that user can view, including their own profile.

Function

viewableProfiles(nodes: int, u: int[], v: int[], queries: int[]) → int[]

Examples

Example 1

nodes = 7u = [2,1,4,5]v = [1,3,5,6]queries = [1,5,7]return = [3,3,1]

Users 1, 2, and 3 are connected, so user 1 can view 3 profiles. Users 4, 5, and 6 form another component. User 7 is isolated and can only view their own profile.

Constraints

  • 1 <= nodes
  • u.length == v.length
  • 1 <= u[i], v[i], queries[i] <= nodes

More Salesforce Online Assessment questions

  • Count Subarrays With Product Equal to KOA · Seen Nov 2026
  • Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
  • Get Message StatusOA · Seen Nov 2026
  • Minimum Unique-Character Segments After DeletionOA · Seen Sep 2026
  • Run-Length String CompressionOA · Seen Sep 2026
  • Maximum Requests in WindowOA · Seen Sep 2026
  • Final Pod Counts After LogsOA · Seen Aug 2026
  • Minimum Removals to Balance ArrayOA · Seen Aug 2026
  • Is This Date a Weekend?OA · Seen Aug 2026
  • Maximum Barbell WeightOA · Seen Jul 2026

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int[] viewableProfiles(int nodes, int[] u, int[] v, int[] queries) {
      // write your code here
    }
}
Checking account…