Quick Overview

This question evaluates proficiency in SQL-based data manipulation and analytics, focusing on time-window filtering, grouping and aggregation (distinct counts and averages), and combining view and reaction event tables.

Calculate Recent Post Views and Reactions for Social Media

Company: Meta

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

info_stream_views +---------+-----------+--------------+----------+------------+ | post_id | viewer_id | relationship | duration | ds | +---------+-----------+--------------+----------+------------+ | 101 | 2001 | Friend | 45.7 | 2023-10-01 | | 102 | 2002 | Unconnected | 67.2 | 2023-10-01 | | 103 | 2003 | Followee | 12.0 | 2023-10-02 | | 104 | 2004 | Unconnected | 80.5 | 2023-10-02 | | 105 | 2005 | Friend | 30.0 | 2023-10-03 | +---------+-----------+--------------+----------+------------+ ​ post_reactions +---------+-----------+-------------+------------+ | post_id | viewer_id | post_action | ds | +---------+-----------+-------------+------------+ | 101 | 2001 | like | 2023-10-01 | | 101 | 2002 | comment | 2023-10-01 | | 102 | 2003 | reshare | 2023-10-02 | | 103 | 2001 | like | 2023-10-02 | | 104 | 2004 | like | 2023-10-03 | +---------+-----------+-------------+------------+ ##### Scenario Info stream engagement analytics for a social media platform; need recent metrics about post views and reactions. ##### Question Write a SQL query to find the number of distinct posts that accumulated at least one view longer than 60 seconds from viewers whose relationship to the author is 'Unconnected' during the last 7 days (relative to today). Write a SQL query to compute the average number of reactions (like, comment, reshare) per post separately for 'Friend' viewers and 'Unconnected' viewers over the last 7 days. ##### Hints Filter last 7 days, use relationship filter, group/aggregate by post and relationship.

Overview: This question evaluates proficiency in SQL-based data manipulation and analytics, focusing on time-window filtering, grouping and aggregation (distinct counts and averages), and combining view and reaction event tables.

Distinct Posts with Long Unconnected Views

Count the number of distinct posts that had at least one Unconnected viewer with a view longer than 60 seconds during the 7-day period from 2025-05-26 to 2025-06-01 (inclusive).

Tables

info_stream_views(post_id INTEGER, viewer_id INTEGER, relationship VARCHAR(20), duration DECIMAL(5,1), ds DATE)

post_reactions(post_id INTEGER, viewer_id INTEGER, post_action VARCHAR(20), ds DATE)

Hints

  1. Filter by relationship = 'Unconnected' and duration > 60 before counting distinct posts.
  2. Use the fixed date window: ds BETWEEN '2025-05-26' AND '2025-06-01'.

Average Reactions Per Post by Relationship

Compute the average number of reactions per post during the 7-day period from 2025-05-26 to 2025-06-01 (inclusive), reported separately for Friend and Unconnected viewers. Determine each reaction's viewer relationship using the latest available view record for that (post_id, viewer_id) pair in info_stream_views.

Tables

info_stream_views(post_id INTEGER, viewer_id INTEGER, relationship VARCHAR(20), duration DECIMAL(5,1), ds DATE)

post_reactions(post_id INTEGER, viewer_id INTEGER, post_action VARCHAR(20), ds DATE)

Hints

  1. First, restrict to reactions where ds is between '2025-05-26' and '2025-06-01'.
  2. Use a window function on info_stream_views to get the latest relationship per (post_id, viewer_id).

Loading coding console...