Posting on consecutive days

window functions

Posting on consecutive days

Meta SQL Interview Question

Meta's growth team treats posting on two days in a row as a sign that a creator is forming a habit.

Find the user_id of every user who posted on two consecutive calendar days at least once. Each user should appear only once.

Asked of

  • Data Analyst
  • Product Analyst
  • Data Scientist
  • Data Engineer
  • ML Engineer
  • AI Engineer

postsTable12 rows

Column NameType
post_idBIGINT
user_idBIGINT
post_typeVARCHAR
created_dateDATE

postsExample Input

post_iduser_idpost_typecreated_date
121photo2024-09-01
222video2024-09-01
321reel2024-09-02
423text2024-09-02
524photo2024-09-03
622photo2024-09-04
723video2024-09-04
824reel2024-09-06

Example Output

user_id
21

Explanation

User 21 posted on September 1 and again on September 2, so they qualify. User 23 posted on September 2 and September 4, and user 24 posted on September 3 and September 6. Those posts are more than a day apart, so neither user qualifies.

The example above is a small slice of the data. Your query runs against the full tables.