← Roku Interview Insights

Roku·Data Scientist·Take-home Assignment·Senior

Senior
Jun 2026Remote

Summary

Roku data science take-home, three SQL problems back to back with a shared schema. The questions were genuinely hard and I spent way longer on them than I expected. Not a vibe check, they clearly wanted to see if you could actually write production-grade SQL.

Questions Asked (3)

Q1

Given a schema with orders, order items, and refunds, write SQL to compute a 7-day rolling gross profit by product category bucket (Speakers vs everything else) for each calendar day in a specified date range. Treat refunds as negative profit applied on the refund date, not the order date.

Product Analytics & MetricsData Modeling
Author's notes

The rolling window part was fine, lag/lead stuff I can do in my sleep.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the schema and business definitions (e.g., gross profit = revenue - cost, refund handling). Then, build a daily profit table by combining order profits and refund profits, bucket product categories into 'Speakers' and 'Other', and finally compute a 7-day rolling sum for each category over the specified date range.

Pro tip: Mention that you would validate the rolling window by checking edge cases (e.g., first 6 days) and ensure refunds are correctly attributed to the refund date, not the order date, to avoid double-counting or misalignment.

1. Clarify schema and definitions

Confirm table structures, join keys, and business definitions for gross profit, refunds, and category bucketing. Ensure you know how to classify products as 'Speakers' vs 'Other'.

2. Compute daily profit from orders

Join orders, order items, and products to calculate profit per order item (revenue - cost). Aggregate by order date and category bucket to get daily order profit.

3. Compute daily profit from refunds

Join refunds with order items and products to calculate refund amounts (as negative profit). Aggregate by refund date and category bucket to get daily refund profit.

4. Combine and fill date range

Union order and refund daily profits, then generate a complete date series for the specified range. Left join to ensure all dates and categories are present, filling missing values with 0.

5. Calculate 7-day rolling gross profit

For each category bucket, compute a 7-day rolling sum of daily gross profit over the date range, using a window function with ROWS BETWEEN 6 PRECEDING AND CURRENT ROW.

Key Points to Mention

  • Handling refunds as negative profit on the refund date, not the order date
  • Bucketing product categories into 'Speakers' and 'Other' using CASE WHEN
  • Using window functions for rolling sums (e.g., SUM() OVER (PARTITION BY category ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW))
  • Ensuring all dates in the range are included, even if no orders/refunds occurred (date spine)
  • Aggregating at the correct grain (daily per category) before applying window function
  • Validating results by checking edge cases and comparing with manual calculations

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

For non-test, non-cancelled orders, identify the top 2 products by week-over-week revenue growth comparing a specific 7-day window to the prior 7 days. Refunds count as negative revenue on the refund timestamp date.

Product Analytics & MetricsRoot Cause Analysis
Author's notes

My first instinct was to just group by product and sum revenue per week then divide.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the exact 7-day window and the definition of 'non-test, non-cancelled orders' and how refunds are handled. Then, write a SQL query that computes net revenue per product for the current and prior 7-day periods, calculates week-over-week growth, and returns the top 2 products by growth. Finally, validate the results and consider edge cases like products with no prior revenue.

Pro tip: Always confirm the date boundaries and whether the comparison is inclusive or exclusive; also, handle division by zero when prior revenue is zero by using NULLIF or a similar function.

1. Clarify requirements and definitions

Confirm the specific 7-day window (e.g., last 7 days vs. a given date range), what constitutes a 'non-test' order (e.g., exclude orders with test flag), and how refunds are recorded (negative revenue on refund date).

2. Compute net revenue per product for current and prior periods

Write a query that aggregates revenue (including refunds as negative) per product for the current 7-day window and the prior 7-day window, ensuring only non-test, non-cancelled orders are included.

3. Calculate week-over-week growth

Compute the growth rate as (current_revenue - prior_revenue) / prior_revenue, handling cases where prior revenue is zero or negative appropriately.

4. Rank and select top 2 products

Order the products by growth rate descending and limit to the top 2, ensuring that only products with sufficient data are considered.

5. Validate and interpret results

Check for anomalies, such as products with very small prior revenue leading to huge growth percentages, and consider whether to filter out such cases or present them with caveats.

Key Points to Mention

  • Definition of 'non-test' orders: exclude orders flagged as test or internal.
  • Handling refunds: treat as negative revenue on the refund timestamp date, not the original order date.
  • Date window logic: use date functions to define the current and prior 7-day periods, ensuring no overlap and correct boundaries.
  • Growth calculation: use (current - prior) / prior, and handle division by zero using NULLIF or CASE statements.
  • Filtering cancelled orders: exclude orders with a cancelled status.
  • Edge cases: products with zero prior revenue, negative prior revenue, or insufficient data; consider minimum revenue thresholds.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

For users whose first event date falls within a given 6-day window, calculate D1 retention rate by country. D1 means the user had any event exactly one calendar day after their first event date.

Product Analytics & MetricsA/B Testing & Experimentation
Author's notes

Straightforward in theory.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the 6-day window and D1 definition, then outline a SQL-based approach: identify each user's first event date, filter to those within the window, and flag D1 retention by checking for any event exactly one day later. Finally, aggregate by country to compute the retention rate as the percentage of retained users.

Pro tip: Mention that you would validate the D1 definition with stakeholders and check for edge cases like time zones or users with multiple events on the same day, as these can significantly impact retention calculations.

1. Clarify requirements and edge cases

Confirm the exact 6-day window, how to handle users with multiple first events, and time zone considerations. Ensure D1 is defined as any event exactly one calendar day after the first event date.

2. Identify first event date per user

Use a subquery or window function to find the minimum event date for each user, ensuring you capture the true first event date.

3. Filter users within the 6-day window

Select only users whose first event date falls within the specified 6-day window (e.g., between start_date and start_date + 5 days).

4. Determine D1 retention

For each user, check if they have any event on the calendar day immediately following their first event date. Flag them as retained if so.

5. Aggregate by country and compute rate

Group by country, calculate the number of retained users divided by total users in the cohort, and express as a percentage.

Key Points to Mention

  • Definition of D1 retention: any event exactly one calendar day after first event date.
  • Handling of time zones and date truncation to ensure calendar day accuracy.
  • Use of window functions (e.g., MIN() OVER) or self-joins to identify first event and D1 activity.
  • Filtering users based on first event date within the 6-day window.
  • Aggregation by country and calculation of retention rate as a percentage.
  • Potential edge cases: users with multiple events on first day, users with no country data, and data completeness.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.