FastPrepDays Between Each User's Latest Two Posts

Days Between Each User's Latest Two Posts

Zip logoZip● MediumFULLTIMEPHONE SCREEN

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

MySQLPostgreSQLPandas

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

ColumnTypeNullableDescription
user_idPKIntegerNo—
display_nameTextNo—

posts

ColumnTypeNullableDescription
post_idPKIntegerNo—
owner_user_idIntegerNo—
creation_dateDateNo—

Foreign key: owner_user_id → users(user_id)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
user_idIntegerNo—
display_nameTextNo—
current_creation_dateDateNo—
days_since_previous_postIntegerNo—

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • users.user_id and posts.post_id are unique.
  • Every posts.owner_user_id references an existing user.
  • creation_date is a calendar date.
  • A larger post_id is 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 problems

See Zip hiring insights