FastPrepHighest-Spend Advertisement
Problem · Database

Highest-Spend Advertisement

MediumCapital One logoCapital OneINTERNNEW GRADOA

Problem statement

An advertising company tracks advertisements, their long and short video versions, broadcasting platforms, and per-video broadcasting statistics.

Find the advertisement on which the company spent the most money. For a statistics row, the broadcasting cost is watch_count * price_per_watch. Count a row only when its platform_id exists in platforms and its video_id is either the long or short version of an advertisement.

Sum the qualifying costs across both versions and every recognized platform for each advertisement.

Result

Return exactly one row with the winning ad_name. Every testcase has a unique highest-spend advertisement.

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.

ads

Advertisement names and the video IDs of their long and short versions.

ColumnTypeNullableDescription
ad_idPKIntegerNo
ad_nameTextNo
long_version_video_idIntegerNo
short_version_video_idIntegerNo

videos

Video-file paths and durations in seconds.

ColumnTypeNullableDescription
video_idPKIntegerNo
pathTextNo
durationIntegerNo

platforms

Recognized broadcasting platforms; contact details may be missing.

ColumnTypeNullableDescription
platform_idPKIntegerNo
contact_mailTextYes
websiteTextYes

ads_statistics

Broadcasting metrics, including exact price per watch.

ColumnTypeNullableDescription
platform_idIntegerNo
video_idIntegerNo
watch_countIntegerNo
total_time_watchedIntegerNo
price_per_watchDecimalNo

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
ad_nameTextNo

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

Constraints

  • Each input table contains at most 2000 rows.
  • ad_id, ad_name, and every advertisement version ID are unique.
  • Every long and short version ID exists in videos, and the two versions of an advertisement are distinct.
  • watch_count and total_time_watched are non-negative signed 64-bit integers.
  • price_per_watch is a non-negative exact decimal value.
  • Statistics may name an unrecognized platform or a video that is not an advertisement version; those rows do not contribute.
  • At least one advertisement has a qualifying statistics row, and the highest total spend is unique.
  • Every per-row cost and per-advertisement total fits in DECIMAL(38, 12).

More Capital One problems