cswork / libraryOpen practice workspace

Coding questions · Meta

Analyze User Engagement Metrics for Video-Calling App

This question evaluates competency in data manipulation and product-metric computation, focusing on combining user profile and call event data to produce user-level engagement measures like participation rates and average call duration.

Calls

+--------+-----------+------------+---------+----------+
| caller | recipient | ds         | call_id | duration |
+--------+-----------+------------+---------+----------+
| 123    | 456       | 2019-01-01 | 4325    | 864.4    |
| 032    | 789       | 2019-01-01 | 9395    | 263.7    |
| 456    | 032       | 2019-01-01 | 0879    | 22.0     |
+--------+-----------+------------+---------+----------+

Users

+---------+-----------+---------+------------+----------+------------+
| user_id | age_bucket| country | primary_os | dau_flag | ds         |
+---------+-----------+---------+------------+----------+------------+
| 123     | 25-34     | US      | iOS        | 1        | 2019-01-01 |
| 456     | 35-44     | France  | Android    | 1        | 2019-01-01 |
| 789     | 25-34     | US      | iOS        | 0        | 2019-01-01 |
+---------+-----------+---------+------------+----------+------------+
Scenario

You work for a video-calling app and need to report user engagement metrics for different geographies.

Question

What percentage of users whose country = 'France' were on at least one video call yesterday?

What is the total video-call duration divided by the number of daily active users (DAU) in the United States today?

Hints

Join the calls table with the user profile table; use DISTINCT user counts, date filters like DATE(ds)=CURRENT_DATE-1 or CURRENT_DATE, and aggregate durations in seconds/minutes before dividing.

France on-call percentage and US duration per DAU (fixed dates)

Using the calls and users tables, compute two engagement metrics for specific dates:

  1. For 2025-05-31, calculate the percentage of users whose country = 'France' that participated in at least one call on that date. Treat both caller and recipient as participants. Return this as a row with:

    • metric_name = 'fr_on_call_pct_yesterday'
    • metric_date = '2025-05-31'
    • metric_value = percentage of French users on at least one call (rounded to 2 decimals).
  2. For 2025-06-01, compute the total person-level call duration for users in the United States on that date divided by the number of US daily active users (dau_flag = 1) on that same date. Again, treat both caller and recipient as participants. Return this as a row with:

    • metric_name = 'us_avg_call_duration_per_dau_today'
    • metric_date = '2025-06-01'
    • metric_value = total US person-level call duration / number of US DAUs (rounded to 2 decimals).

Your query should return exactly two rows (one for each metric) with columns: metric_name, metric_date, metric_value.

Table calls

columntypeconstraints
callerVARCHARNOT NULL
recipientVARCHARNOT NULL
dsDATENOT NULL
call_idVARCHARPRIMARY KEY, NOT NULL
durationDECIMAL(10,1)NOT NULL

Sample data:

call_idcallerdsdurationrecipient
43251232025-05-31864.4456
93950322025-05-31263.7789
08794562025-05-3122032
50011232025-06-01600456
50024562025-06-01300789

Table users

columntypeconstraints
user_idVARCHARNOT NULL
age_bucketVARCHARNOT NULL
countryVARCHARNOT NULL
primary_osVARCHARNOT NULL
dau_flagINTEGERNOT NULL
dsDATENOT NULL

Sample data:

age_bucketcountrydau_flagdsprimary_osuser_id
25-34US12025-05-31iOS123
35-44France12025-05-31Android456
25-34US02025-05-31iOS789
25-34US12025-06-01iOS123
35-44France12025-06-01Android456
25-34US12025-06-01iOS789

Expected output

Two rows: (1) percentage of French users who were on at least one call on 2025-05-31, and (2) total person-level call duration for US users on 2025-06-01 divided by the number of US DAUs on 2025-06-01. Based on the sample data, all French users (only user 456) were on a call on 2025-05-31, and US users on 2025-06-01 (123 and 789) accumulated 900 seconds of person-level call duration over 2 DAUs.

metric_datemetric_namemetric_value
2025-05-31fr_on_call_pct_yesterday100
2025-06-01us_avg_call_duration_per_dau_today450

Hints

  1. Treat both caller and recipient as participants by UNION ALL-ing them into a single call_participants table.
  2. Filter by explicit dates: use ds = DATE '2025-05-31' for the France percentage and ds = DATE '2025-06-01' for the US duration metric.
  3. For the France metric, compute distinct French users on calls divided by total French users; for the US metric, sum durations for US participants and divide by the count of US users with dau_flag = 1.
  4. Use NULLIF in denominators to avoid divide-by-zero errors and ROUND(...) to 2 decimal places.