Back to questions

Event Friends Recommendation Facebook SQL Interview Question

Event Friends Recommendation

Facebook SQL Interview Question

Facebook wants to recommend new friends to people who show interest in attending 2 or more of the same private events.

Sort your results in order of user_a_id and user_b_id (refer to the Example Output below).

Notes:

  • A user interested in attending would have either 'going' or 'maybe' as their attendance status.
  • Friend recommendations are unidirectional, meaning if user x and user y should be recommended to each other, the result table should have both user x recommended to user y and user y recommended to user x.
  • The result should not contain duplicates (i.e., user y should not be recommended to user x multiple times).

Table:

Column NameType
user_a_idinteger
user_b_idinteger
statusenum ('friends', 'not_friends')

Each row of this table indicates the status of the friendship between user_a_id and user_b_id.

Example Input:

user_a_iduser_b_idstatus
111333not_friends
222333not_friends
333222not_friends
222111friends
111222friends
333111not_friends

Table:

Column NameType
user_idinteger
event_idinteger
event_typeenum ('public', 'private')
attendance_statusenum ('going', 'maybe', 'not_going')
event_datedate

Example Input:

user_idevent_idevent_typeattendance_statusevent_date
111567publicgoing07/12/2022
222789privategoing07/15/2022
333789privatemaybe07/15/2022
111234privatenot_going07/18/2022
222234privategoing07/18/2022
333234privategoing07/18/2022

Example Output:

user_a_iduser_b_id
222333
333222

Users 222 and 333 who are not friends have shown interest in attending 2 or more of the same private events.

The dataset you are querying against may have different input & output - this is just an example!

Input

Output