← Instacart Interview Insights
Part A was fine, date_trunc to Monday and filter on status = completed, standard stuff.
Break the problem into three clear parts: first, compute weekly revenue by filtering out cancelled/refunded orders and aggregating revenue components by ISO week; second, identify the last two complete weeks relative to the latest timestamp and calculate the percent change; third, if the drop is 4% or more, attribute the decline to geos by computing each geo's revenue delta and its share of the total delta, then rank and return the top 3.
Pro tip: Always clarify how 'complete week' is defined relative to the latest timestamp—e.g., whether the latest timestamp is in the current week and should be excluded—and explicitly state your assumptions about ISO week boundaries and time zones.
Calculate revenue as subtotal + tax + delivery_fee - discount, and exclude orders with status 'cancelled' or 'refunded'. Ensure you handle NULLs appropriately.
Use ISO week functions (e.g., EXTRACT(ISOYEAR FROM timestamp), EXTRACT(WEEK FROM timestamp)) to group revenue by week. Sum revenue per week.
Find the latest timestamp in the data, determine the most recent complete ISO week (excluding the current partial week), and select the two most recent complete weeks.
Calculate the percent change between the last two complete weeks. If the drop is 4% or more, proceed to geo-level analysis.
For the two weeks, compute revenue per geo, calculate each geo's revenue delta (current week - prior week), its share of the total revenue delta, and its own week-over-week percent change. Rank geos by absolute revenue decline and return the top 3.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.