Skip to content

Plays that were immediately replayed

EasyFreeRunning totals, LAG and LEAD9 min2 hidden datasets

The task

The recommendations team wants to find tracks that listeners loved enough to play again straight away.

A play is an immediate replay candidate when the same listener's next play, by played_at, is of the same track. The next play is the listener's play with the earliest played_at after this one, whatever the date and whatever the track. If two plays of a listener share the same played_at, the lower play_id is first.

Consider only plays that started in June 2025 (from 2025-06-01 up to, but not including, 2025-07-01). Their next play may be on a later date, even in July.

Return the plays that are followed by a play of the same track:

  • play_id
  • listener_id
  • track_id
  • played_at
  • replayed_at: the played_at of the next play

Sort by played_at, then play_id.

Expected output

play_idlistener_idtrack_idplayed_atreplayed_at
  • Sorted by played_at ascending, then play_id ascending.
  • Checked on the sample and on 2 hidden datasets. How grading works

Tables Music streaming service · click a name to insert it

listeners180 rows in the sample

One row per listener account. Key: listener_id.

intUnique id.
dateDay they joined.
textTwo-letter country code.
textfree, premium or family.
artists30 rows in the sample

One row per artist. Key: artist_id.

intUnique id.
textName.
textpop, rock, hip-hop, electronic, jazz or folk.
tracks116 rows in the sample

One row per track. Key: track_id.

intUnique id.
textTrack title.
intMain artist.
intLength.
dateRelease day.
plays6,555 rows in the sample

One row per play. Key: play_id.

bigintUnique id.
intWho listened.
intWhat.
timestampStart time (UTC).
intHow long they listened.
textphone, desktop, speaker or car.

Related questions

Loading the editor and PostgreSQL