Skip to content

Streaks of four or more days of opening the app

MediumFull bankGaps and islands18 min2 hidden datasets

The task

The engagement team wants to find habit-forming users. A user has an app-open day when they fire at least one app_open event on that UTC calendar day. A streak is a run of consecutive app-open days with no day missing in between. A user can have several streaks, and one day with several app_open events is still one day.

Return every streak that lasts 4 days or more:

  • user_id
  • streak_start: the first day of the streak (a date)
  • streak_end: the last day of the streak (a date)
  • streak_days: how many days the streak lasts

A streak is reported in full: if a user opens the app on 5 days in a row, the answer has one row with streak_days 5, not two rows. Sort by user_id, then streak_start.

Expected output

user_idstreak_startstreak_endstreak_days
  • Sorted by user_id ascending, then streak_start ascending.
  • Checked on the sample and on 2 hidden datasets. How grading works

Tables Mobile shopping app · click a name to insert it

users360 rows in the sample

One row per user. Key: user_id.

intUnique id.
timestampSign-up time (UTC).
textTwo-letter country code.
textios, android or web.
textorganic, paid, referral or partner. NULL when unknown.
events7,616 rows in the sample

One row per tracked event. Key: event_id.

bigintUnique id.
intWho fired it.
textapp_open, search, view_item, add_to_cart, begin_checkout, purchase or share.
timestampWhen (UTC).
textSession the event belongs to. NULL for a few events sent from the background.
numeric(10,2)Order value for purchase events, NULL otherwise.
experiment_assignments349 rows in the sample

Which variant each user saw in each experiment. Key: user_id, experiment.

intThe user.
textnew_onboarding or one_tap_checkout.
textcontrol or treatment.
timestampWhen the user was assigned (UTC).

Related questions

Loading the editor and PostgreSQL