Median Minutes from Add to Cart to Purchase on Facebook Shops

Last updated: November 29, 2026

Quick Overview

For each shop, compute the median time between a user's first add-to-cart and their first purchase that follows it within the same day, using only carts that did convert.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


For each shop, compute the median time between a user's first add-to-cart and their first purchase that follows it within the same day, using only carts that did convert.

Typical of Meta's commerce analytics screens, where time-between-steps is the second half of every funnel question. The interviewer checks pairing logic (which cart goes with which purchase), use of an approximate or exact median, and whether you surface the non-converting share.

What the Interviewer Expects
  • Pairs each first add-to-cart with the first purchase after it
  • Limits pairing to a sensible window and states it
  • Uses an appropriate median function for the engine
  • Groups by shop and reports volume alongside the median
  • Notes survivorship: the median covers converters only
Key Topics to Cover
time between steps
median
approx_percentile
event pairing
commerce funnel
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 include carts that never converted, for example with survival analysis?
  • Why might median be preferred over mean here?
  • How would you get this per user cohort instead of per shop?
  • What if a purchase can include items added in an earlier session?
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

shop_events(user_id, shop_id, event_name, event_ts) with add_to_cart and purchase. For each (user, shop, day) I take the first add-to-cart, then the first purchase at or after it on the same day...

Approach

Aggregate first add-to-cart per (user, shop, day). Join purchases on the same keys with purchase_ts >= cart_ts and take the minimum. Compute minutes between them, then the median per shop. In Presto...


Submit Your Answer
Markdown supported