Days Between Each User's Latest Two Posts
Updated
Problem statement
You are given a users table and a posts table from a forum. For every user who has at least one post, return that user's current post and the number of calendar days since the immediately previous post.
The current post is the user's latest post by creation_date. When dates tie, the larger post_id is later. The previous post is the next row in that same ordering.
Return user_id, display_name, current_creation_date, and days_since_previous_post. A user with exactly one post has a day difference of 0. Users with no posts are omitted.
Order rows by current_creation_date from newest to oldest, then by user_id ascending.
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
users
| Column | Type | Nullable | Description |
|---|---|---|---|
| user_idPK | Integer | No | — |
| display_name | Text | No | — |
posts
| Column | Type | Nullable | Description |
|---|---|---|---|
| post_idPK | Integer | No | — |
| owner_user_id | Integer | No | — |
| creation_date | Date | No | — |
Foreign key: owner_user_id → users(user_id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| user_id | Integer | No | — |
| display_name | Text | No | — |
| current_creation_date | Date | No | — |
| days_since_previous_post | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
users.user_idandposts.post_idare unique.- Every
posts.owner_user_idreferences an existing user. creation_dateis a calendar date.- A larger
post_idis later when one user's creation dates tie. - Users with no posts are omitted; users with one post have a day difference of
0.
More Zip Phone Screen questions
- Maximum Survival Time in a Graph PursuitPHONE SCREEN · Seen Sep 2026
- Find All Zip Rummy MeldsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
- Shortest Path Around Moving ParadesPHONE SCREEN · Seen Mar 2026
- Furthest Building with Sandbags and RopesPHONE SCREEN · Seen Feb 2026
- Phrase Covering the Most WordsPHONE SCREEN · Seen Feb 2026
- Translate Values in a Nested MapPHONE SCREEN · Seen Feb 2026
- Maximum Nonadjacent Sum in a General TreePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2025
- Shortest Distance in a GraphPHONE SCREEN · Seen Nov 2025
- Open the Lock and Return a Shortest PathPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2025
- Winning Draws for a Mahjong HandPHONE SCREEN · Seen Sep 2025
Similar questions at other companies
- Nth Highest SalaryPaytm · PHONE SCREENPaytm interview questions
- Email Funnel: Opened Within a Day, Replied Within a WeekSuperhuman · PHONE SCREENSuperhuman interview questions
- iPhone Model Sales Share by CountryApple · PHONE SCREENApple interview questions
- Top Three Accounts by Monthly Transaction AmountMastercard · PHONE SCREENMastercard interview questions
- In-Memory Database QueriesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Top Three Sales per County and YearClickhouse · PHONE SCREEN
- Block Type with the Most ChildrenNotion · PHONE SCREENNotion interview questions
- Third-Highest Known SalaryAdobe · PHONE SCREENAdobe interview questions
- Observed-User Percentage by AppMicrosoft · PHONE SCREENMicrosoft interview questions
- Nth-Highest Book Sales VolumeAmazon · PHONE SCREEN