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
November 29, 20260
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
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- 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 ProblemsSample 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...