Company: Visa SWE_18july
Difficulty: medium
Implement a prototype of a friend recommendation system for a social media application. There are n users indexed from 0 to n-1 , and m friendships are represented as a 2D array friendships , where the i th friendship is a connection between users friendships[i][0] and friendships[i][1] . Friendship is mutual. A user x is suggested as a friend to user y if: x and y are not already friends (and x ≠ y ); x and y have at least one common friend, and among all such candidates x has the maximum number of common friends with y (friends that both x and y are connected to); if multiple users satisfy conditions 1 and 2, the user with the minimum index is recommended. Given n and friendships , for each of the n users find the index of the friend that should be recommended to them. If there is no recommendation available — that is, no non-friend shares at least one common friend with the user — report -1 . Example Suppose n = 5 , m = 5 and friendships = [[0, 1], [0, 2], [1, 3], [2,