← Instacart Interview Insights
The filter part is easy, the tricky bit is getting 'last 8 full calendar weeks' right.
Start by clarifying the definition of 'last 8 full calendar weeks' (e.g., weeks starting Monday or Sunday, excluding the current incomplete week) and 'standard delivery orders' (e.g., delivery_type = 'standard'). Then write a query that filters orders to the date range, groups by week, and aggregates revenue and order count. Use a CTE or subquery to handle date boundaries cleanly.
Pro tip: Always confirm the week-start convention and time zone with the interviewer; a one-day offset can change results. Also, consider whether to include weeks with zero orders—if so, use a calendar table or generate_series to left join and fill gaps.
Ask about the definition of 'full calendar weeks' (start day, time zone) and 'standard delivery orders' (specific status or type). Confirm whether to include weeks with no orders and the expected output format (e.g., one row per week or overall totals).
Calculate the start and end dates for the last 8 full weeks. For example, if weeks start on Monday, find the most recent Monday that begins a full week (i.e., the Monday of the previous week) and go back 7 weeks to get the start date.
Write the main query to filter orders to the date range and standard delivery, then group by week (using DATE_TRUNC or equivalent) and compute SUM(revenue) and COUNT(order_id).
If the interviewer wants all 8 weeks even with zero orders, use a calendar table or generate_series to create a complete list of weeks and LEFT JOIN the aggregated results.
Check for edge cases (e.g., time zone conversions, null values) and consider indexing on date and delivery_type for performance. Present the final query clearly.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.