Clearing Price as the Second-Highest Bid in Each Ad Auction

Last updated: November 29, 2026

Quick Overview

Given every bid submitted in a set of ad auctions, return each auction's winner and its clearing price, defined as the second-highest bid. Ties on the top bid go to the earlier bid, and a single-bidder auction clears at a reserve price of 0.01.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Online Assessment
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given every bid submitted in a set of ad auctions, return each auction's winner and its clearing price, defined as the second-highest bid. Ties on the top bid go to the earlier bid, and a single-bidder auction clears at a reserve price of 0.01.

Meta's ads auction is a generalized second-price style system, and analysts reasoning about advertiser costs are expected to be comfortable with it. The question checks ROW_NUMBER or LEAD with a careful ordering, plus explicit handling of the one-bidder edge case.

What the Interviewer Expects
  • Ranks bids within each auction by amount descending with a time tie-break
  • Pulls the second row's amount with conditional aggregation or LEAD
  • Returns the reserve price when there is no second bid
  • Notes that a tie on the top bid makes clearing price equal the winning bid
  • Keeps one output row per auction
Key Topics to Cover
ROW_NUMBER
LEAD
second-price auction
conditional aggregation
edge cases
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you compute the average discount between winning bid and clearing price per advertiser?
  • Real Meta auctions rank by total value (bid times estimated action rate plus quality), not raw bid. How would the query change?
  • How would you find advertisers who win often but always at a clearing price close to their own bid?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Table: bids(auction_id, advertiser_id, bid_amount, bid_ts). I assume each advertiser bids at most once per auction and amounts are in USD. Ties: the earlier bid_ts wins....

Approach

Order bids within each auction by bid_amount DESC, bid_ts ASC and number them. Row 1 is the winner. Row 2's amount is the clearing price. Pivot rows 1 and 2 back into one row with conditional MAX,...


Submit Your Answer
Markdown supported