Interview Core Track · Medium · 25 min
2081 Recommendation System
-- Problem Statement: -- You are given the list of Facebook friends and the list of Facebook pages that users follow. Your task is to create a new recommenda...
Company labels are directional practice context, not official interview guidance.
Objective
Practice joins through a Facebook-tagged business scenario.
Approach
Use this track to improve speed, edge-case handling, and accuracy under timed conditions.
Company context
Company labels are directional practice context, not official interview guidance.
-- Problem Statement: -- You are given the list of Facebook friends and the list of Facebook pages that users follow. Your task is to create a new recommendation system for Facebook. -- For each Facebook user, find pages that this user doesn't follow but at least one of their friends does. Output the user ID and the ID of the page that should be recommended to this user. -- Solution 1: using NOT IN SELECT DISTINCT f.user_id, p.page_id FROM users_friends f JOIN users_pages p ON f.friend_id = p.user_id WHERE (f.user_id, p.page_id) NOT IN (SELECT user_id, page_id FROM users_pages) -- Solution 2: using NOT EXISTS SELECT DISTINCT f.user_id, p.page_id FROM users_friends f JOIN users_pages p ON f.friend_id = p.user_id WHERE NOT EXISTS ( SELECT * FROM users_pages pg WHERE pg.user_id = f.user_id and pg.page_id = p.page_id )
This is a Pro question
Upgrade to Pro to unlock this prompt, the SQL workspace, and all 254 problems.
Upgrade to Pro — unlock all 254 problemsSQL workspace
Run queries against the protected question data, then submit once the result shape looks right.
Sign in to run SQL
Create a free account or sign in before running queries against protected question data.