← Amazon Interview Insights

Amazon·Data Scientist·Technical Phone Screen·Senior

Senior
May 2026

Summary

Amazon Data Scientist technical screen, heavy SQL and pandas. Two-part problem with a tricky de-duplication rule baked in that you had to carry through both parts consistently. Felt more like a take-home in spirit but delivered live.

Questions Asked (2)

Q1

Write a single SQL query (no temp tables, no correlated subqueries) that applies a same-day order de-duplication rule, then returns one row per kept order per customer with columns for order revenue, a 3-day rolling revenue window, and a dense rank by revenue over the last 7 days. Only customers with at least two completed orders in that window should appear.

Data ModelingProduct Analytics & MetricsTechnical Trade-offs
Author's notes

This one took me a while to even parse.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the de-duplication rule and window definitions, then outline a single-query plan using CTEs with window functions to handle deduplication, rolling revenue, and ranking. Emphasize that the final filter for customers with at least two completed orders must be applied after aggregation, and ensure the query avoids temp tables and correlated subqueries.

Pro tip: Mention that you would validate the de-duplication rule with a quick data profile (e.g., checking for same-day duplicates) and confirm whether the 7-day window is inclusive of the current day, as these details often trip up candidates.

1. Clarify requirements and edge cases

Ask about the exact de-duplication rule (e.g., keep the latest order per customer per day), the definition of 'completed' orders, and whether the 3-day and 7-day windows are rolling and inclusive. Confirm that the final output should only include customers with at least two completed orders in the 7-day window.

2. Deduplicate same-day orders

Use a window function like ROW_NUMBER() partitioned by customer and order date, ordered by a timestamp or order ID, to select one order per customer per day. This ensures no duplicate same-day orders are counted.

3. Compute rolling metrics and rank

For each kept order, calculate the 3-day rolling revenue sum using a window function with ROWS BETWEEN 2 PRECEDING AND CURRENT ROW, and compute DENSE_RANK() over revenue within the last 7 days using a window frame of RANGE BETWEEN 6 PRECEDING AND CURRENT ROW (or equivalent).

4. Filter customers with at least two completed orders

After computing the metrics, apply a filter to include only customers who have at least two completed orders within the 7-day window. This can be done using a COUNT() window function or a HAVING clause in a subquery.

5. Assemble final query and validate

Combine the steps into a single SQL query using CTEs for readability, ensuring no temp tables or correlated subqueries. Walk through the logic with a small example to validate correctness.

Key Points to Mention

  • Use of window functions (ROW_NUMBER, SUM OVER, DENSE_RANK) to avoid temp tables and correlated subqueries.
  • Definition of the de-duplication rule: keep one order per customer per day, likely the latest by timestamp.
  • Rolling window calculations: 3-day rolling revenue sum and 7-day dense rank, with proper frame specifications.
  • Filtering condition: only customers with at least two completed orders in the 7-day window.
  • Handling of date boundaries and ensuring the windows are inclusive of the current row.
  • Performance considerations: indexing on customer and order date, and avoiding unnecessary sorting.

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

Q2

Using pandas, produce a per-customer summary DataFrame for the last 7 days containing total revenue, the top product category by revenue (alphabetical tiebreak), and that category's share of total revenue. Apply the same same-day de-duplication rule before any aggregation, and do it without Python row-level loops.

Data ModelingProduct Analytics & MetricsAlgorithms & Data Structures
Author's notes

The no-loops constraint is the real test.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, filter the data to the last 7 days and apply same-day de-duplication by keeping the first transaction per customer-product-day (or per transaction ID). Then, aggregate revenue per customer and category, compute total revenue per customer, and derive the top category and its share using vectorized operations like groupby, transform, and idxmax.

Pro tip: Explicitly state your de-duplication rule (e.g., drop_duplicates on customer_id, product_id, date) and justify it; this shows you understand data quality and business logic. Also, mention that you avoid loops by using groupby and transform, which is crucial for scalability.

1. Filter and de-duplicate

Filter the DataFrame to the last 7 days based on the date column. Apply same-day de-duplication by dropping duplicate rows per customer, product, and date, keeping the first occurrence.

2. Aggregate revenue by customer and category

Group by customer and product category, summing revenue to get total revenue per category per customer. Use groupby and sum with reset_index.

3. Compute total revenue per customer

Calculate the total revenue per customer by summing across categories, and merge or broadcast this back to the category-level DataFrame using transform or merge.

4. Identify top category and share

For each customer, find the category with the highest revenue (alphabetical tiebreak) using sort_values and drop_duplicates or idxmax. Compute the share as category revenue divided by total revenue.

5. Produce final summary DataFrame

Select and rename columns to customer_id, total_revenue, top_category, and category_share. Ensure the output is a clean DataFrame with one row per customer.

Key Points to Mention

  • Same-day de-duplication rule: specify the key (e.g., customer_id, product_id, date) and keep='first' or 'last'.
  • Use of vectorized pandas operations: groupby, transform, merge, sort_values, drop_duplicates, idxmax.
  • Handling ties alphabetically: sort by revenue descending and category ascending before picking top.
  • Computing share: category revenue divided by total revenue per customer.
  • Avoiding Python loops: emphasize that all steps are vectorized.
  • Data types and date filtering: ensure date column is datetime and filter using pd.Timestamp.now() - pd.Timedelta(days=7).

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