Problem · Database
Highest Version B Viewing Week
Problem statement
A video-streaming company compares two versions of its ads. The experiment_metrics table contains one aggregated row for every date and time slot in a calendar month.
Find the complete Monday-to-Sunday week with the greatest total user_time_spent_version_b_in_mins. Sum that column across every time slot and all seven dates in the week.
Weekly selection
- A week is complete only when all seven calendar dates from Monday through Sunday occur in the input.
- Ignore partial weeks at the beginning or end of the month.
- If several complete weeks have the same greatest total, choose the earliest Monday.
Return exactly one row with week_start and week_end.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
experiment_metrics
Daily time-slot aggregates for the combined experiment and version B.
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | — |
| metric_date | Date | No | — |
| time_slot | Text | No | — |
| total_user_time_spent_in_mins | Integer | No | — |
| total_ads_watched_in_mins | Integer | No | — |
| ads_clicked | Integer | No | — |
| user_time_spent_version_b_in_mins | Integer | No | — |
| ads_watched_version_b_in_mins | Integer | No | — |
| ads_clicked_version_b | Integer | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| week_start | Date | No | — |
| week_end | Date | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
experiment_metricscontains every date in one calendar month.- Every date has the same positive number of distinct time slots.
idvalues are unique.- At least one complete Monday-to-Sunday week exists.
- All minute and click counts are non-negative signed 64-bit integers.
- Every weekly sum fits in a signed 64-bit integer.
- A testcase contains at most
2000rows.