Company: Visa SWE_18july

Difficulty: medium

Problem Statement

Friend Recommendation System A social network has n users, indexed from 0 to n - 1 , and m friendships. Friendship is mutual: if a is a friend of b , then b is a friend of a . For a pair of users x and y , a common friend is a user who is a friend of x and a friend of y at the same time. The prototype recommends exactly one friend to each user y , chosen like this: Only a user x with x != y that is not already a friend of y may be recommended. Such an x is a candidate only if x and y have at least one common friend. Among the candidates, the one sharing the largest number of common friends with y is recommended. If several candidates share that largest number, the one with the smallest index is recommended. If user y has no candidate at all — every other user is either already a friend of y or shares no friend with y — then y gets no recommendation and the answer for y is -1 . Report the recommendation of every user. Input Format The first line contains a single integer n , the number

More Visa SWE_18july OA questionsInterview experiences