Feed Impression

Start Timer

0:00:00

Let’s say you work at Pinterest. On Pinterest’s internal database, the table pins contains an identifier number and creation date/time of pins (content such as pictures or videos) that a user posted on his profile.

The table event_log is a log table containing data about all actions on pins.

Possible action types are:

  • "View" - Logged when pins appear on a user’s screen.
  • "Engagement" - Logged when actions such as saves or pin-clicks occur.

Write a query to determine the percentage of users that have viewed at least one content within seven days from the content being posted and with at least one engagement recorded on any pin, regardless of when it occurred.

A view counts as within seven days when its date is at most 7 calendar days after the pin’s creation date. Divide by all distinct users in event_log, and return the share as a decimal between 0 and 1 (0.6 means 60%).

Example:

Input:

pins table

Columns Type
pin_id INTEGER
created_at DATETIME

event_log table

Columns Type
event_id INTEGER
pin_id INTEGER
user_id INTEGER
action_type VARCHAR
action_date DATETIME

Output:

Columns Type
percent_of_users FLOAT
.
.
.
.
.


Comments

Loading comments