← Thumbtack Interview Insights
This one had a lot of layers and I underestimated the timezone piece at first.
Start by generating a complete series of weeks covering the date range using generate_series, then left join aggregated transaction data to include zero-activity weeks. Compute the rolling sum with a window function over the ordered weeks, ensuring missing weeks are treated as zero. Handle time zone conversion to America/Los_Angeles and week truncation to Monday carefully.
Pro tip: Explicitly state that you're using generate_series to build the calendar and that you'll convert timestamps to local time before truncating to week, because time zone handling is a common pitfall. Also mention that you'd validate the query against edge cases like DST transitions and partial weeks.
Use generate_series to produce a series of week start dates (Mondays) covering the entire date range, ensuring no gaps. This forms the base calendar.
Convert transaction timestamps to America/Los_Angeles, truncate to week (Monday start), and sum amounts per week. This yields actual weekly totals.
Left join the generated weeks to the aggregated weekly totals, replacing NULLs with 0 to include zero-activity weeks.
Use a window function (SUM with ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) over the ordered weeks to calculate the rolling sum, treating missing weeks as zero.
Select the week start date, weekly total, and rolling sum, ordered chronologically. Ensure the query is a single statement using CTEs for clarity.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.