Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs

Back to Questions

7. Ad Impressions Count

easy
MetaMeta
senior

What is the total number of ad impressions each ad received in ads_actions, treating each row as a single impression regardless of clicked_ad? Return ad_name and ad_impressions, grouped by ad_name, and order the results by ad_impressions descending, then ad_name ascending.

ads_actions
Column NameType
ad_exp_idint64
ad_nameobject
cpc_rateobject
clicked_adint64
Expected Output Schema
Column NameType
ad_nameobject
ad_impressionsint64

Constraints

  • Output columns: ad_name, ad_impressions

  • Count rows; ignore clicked_ad values

  • Sort impressions DESC, name ASC

Hint 1

Treat every row in ads_actions as one impression; don’t use clicked_ad at all.

Hint 2

Group by ad_name and count rows per group using COUNT(*).

Hint 3

After aggregating, sort by impressions descending, then ad_name ascending to break ties.

Roles
Data Scientist
Data Analyst
Data Engineer
Companies
MetaMeta
Levels
senior
entry
Tags
sql
pandas
group-by
aggregation
sorting
16 people are solving this problem
Python LogoPython Editor
Ln 1, Col 1

Input Arguments

Edit values below to test with custom inputs

You need tolog in/sign upto run or submit