FastPrepHighest Version B Viewing Week
Problem · Database

Highest Version B Viewing Week

EasyCapital One logoCapital OneNEW GRADINTERNOA

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.

ColumnTypeNullableDescription
idPKIntegerNo
metric_dateDateNo
time_slotTextNo
total_user_time_spent_in_minsIntegerNo
total_ads_watched_in_minsIntegerNo
ads_clickedIntegerNo
user_time_spent_version_b_in_minsIntegerNo
ads_watched_version_b_in_minsIntegerNo
ads_clicked_version_bIntegerNo

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
week_startDateNo
week_endDateNo

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • experiment_metrics contains every date in one calendar month.
  • Every date has the same positive number of distinct time slots.
  • id values 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 2000 rows.

More Capital One problems