← Boston Consulting Group Interview Insights
This one took me longer to structure than I expected.
Break the problem into three parts: first compute per-model revenue for the current and prior 7-day windows using conditional aggregation on completed orders; second rank customers by spend in the current window per model, using a tie-breaker on earliest purchase date; third combine these to get top 3 customers with their revenue share and week-over-week growth. Use CTEs to keep the query modular and readable.
Pro tip: Clarify the definition of '7-day window' (e.g., rolling 7 days ending today vs. fixed calendar weeks) and confirm that 'completed orders' means status = 'completed'. Also, mention that you'd handle ties in the top-3 ranking using ROW_NUMBER() with a deterministic tie-breaker, and consider performance implications of window functions on large datasets.
Determine the date ranges for the current and prior 7-day windows (e.g., using CURRENT_DATE - INTERVAL '7 days'). Filter the orders table to only include completed orders.
Use conditional aggregation (SUM(CASE WHEN ...)) to calculate total revenue per car model for the current and prior windows in a single pass or via separate CTEs.
For each model, rank customers by their total spend in the current window. Use ROW_NUMBER() with ORDER BY spend DESC, earliest_purchase_date ASC to break ties.
Filter to the top 3 ranked customers per model, and calculate each customer's share as their spend divided by the model's total current-window revenue.
Compute growth as (current_revenue - prior_revenue) / prior_revenue. Join the revenue and top-customer results to produce the final per-model output.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.