Skip to content

Listening sessions split by a 30-minute gap

HardFull bankGaps and islands22 min2 hidden datasets

The task

The product team defines a listening session from play timestamps alone. Use plays that started in the first week of June 2025 (from 2025-06-01 up to, but not including, 2025-06-08).

For each listener, order their plays in that week by played_at, then play_id. A play starts a new session when it is the listener's first play of the week, or when more than 30 minutes have passed since the played_at of the listener's previous play in that week. A gap of exactly 30 minutes does not start a new session. Plays that are not separated by a bigger gap belong to the same session. Do not look at plays before June 1.

Return one row per listener who has at least one play in the week:

  • listener_id
  • sessions: the number of sessions
  • longest_session_plays: the number of plays in the listener's biggest session

Sort by listener_id.

Expected output

listener_idsessionslongest_session_plays
  • Sorted by listener_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