cswork / libraryOpen practice workspace

Coding questions · Confluent

Determine Tutorial Completion Rate by Variant in 7 Days

This question evaluates a candidate's competency in data manipulation and event-based analytics, focusing on skills such as joining user and event tables, aggregating event data, and computing cohort completion metrics by variant.

users

| user_id | sign_up_at | tutorial_variant |
| 101 | 2023-08-01 | original |
| 102 | 2023-08-02 | variant |
| 103 | 2023-08-02 | original |
| 104 | 2023-08-03 | variant |
| 105 | 2023-08-03 | original |

tutorial_events

| event_id | user_id | step_index | event_time |
| 1 | 101 | 1 | 2023-08-01 10:00:00 |
| 2 | 101 | 2 | 2023-08-01 10:02:00 |
| 3 | 102 | 1 | 2023-08-02 11:00:00 |
| 4 | 104 | 1 | 2023-08-03 09:00:00 |
| 5 | 105 | 1 | 2023-08-03 12:00:00 |
Scenario

Confluent wants to understand the impact of two onboarding-tutorial variants (original vs variant) on tutorial completion.

Question

Given the tables below, write a SQL query that returns, for each tutorial_variant, the share of signed-up users who reach the maximum step_index (i.e., complete the tutorial) within 7 days of their sign_up_at date.

Hints

Join users with tutorial_events, find each user’s max step, compare to global max per variant, filter by 7-day window, then aggregate.

Tutorial completion rate by variant within 7 days of signup

Confluent wants to understand the impact of two onboarding-tutorial variants (original vs variant) on tutorial completion. Given the tables users and tutorial_events, write a SQL query that returns, for each tutorial_variant, the share of signed-up users who reach that variant’s maximum tutorial step (maximum step_index observed for that variant) within 7 days of their sign_up_at date. The output should have one row per tutorial_variant with columns tutorial_variant and completion_rate (completed users within 7 days divided by total signed-up users for that variant).

Table users

columntypeconstraints
user_idINTEGERPRIMARY KEY, NOT NULL
sign_up_atDATENOT NULL
tutorial_variantVARCHAR(20)NOT NULL

Sample data:

sign_up_attutorial_variantuser_id
2023-08-01original101
2023-08-02variant102
2023-08-02original103
2023-08-03variant104
2023-08-03original105

Table tutorial_events

columntypeconstraints
event_idINTEGERPRIMARY KEY, NOT NULL
user_idINTEGERNOT NULL, FOREIGN KEY REFERENCES users(user_id)
step_indexINTEGERNOT NULL
event_timeTIMESTAMPNOT NULL

Sample data:

event_idevent_timestep_indexuser_id
12023-08-01 10:00:001101
22023-08-01 10:02:002101
32023-08-02 11:00:001102
42023-08-03 09:00:001104
52023-08-03 12:00:001105

Expected output

One row per tutorial_variant with the completion_rate (completed users within 7 days divided by total signed-up users for that variant). In this data, the original variant has a 2-step tutorial (max step_index = 2) and the variant tutorial has a 1-step tutorial (max step_index = 1). Only user 101 completes the original tutorial, and both users 102 and 104 complete the variant tutorial.

completion_ratetutorial_variant
0.3333original
1variant

Hints

  1. Join users to tutorial_events and restrict events to the 7-day window from each user’s sign_up_at.
  2. Compute each user’s maximum step_index within that 7-day window.
  3. Compute the global maximum step_index per tutorial_variant across all its users.
  4. Mark a user complete if their 7-day max equals their variant’s global max, then aggregate by variant to get the share.