
Posting on consecutive days
hardPosting 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 Name | Type |
|---|---|
| post_id | BIGINT |
| user_id | BIGINT |
| post_type | VARCHAR |
| created_date | DATE |
postsExample Input
| post_id | user_id | post_type | created_date |
|---|---|---|---|
| 1 | 21 | photo | 2024-09-01 |
| 2 | 22 | video | 2024-09-01 |
| 3 | 21 | reel | 2024-09-02 |
| 4 | 23 | text | 2024-09-02 |
| 5 | 24 | photo | 2024-09-03 |
| 6 | 22 | photo | 2024-09-04 |
| 7 | 23 | video | 2024-09-04 |
| 8 | 24 | reel | 2024-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.
Company
Meta
Difficulty
hard
Topic
window functions
Your query
Starting the SQL engine...