← Coinbase Interview Insights

Coinbase·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

SQL technical screen for a Data Scientist role at Coinbase. One question, pretty focused, window functions were clearly the expected path.

Questions Asked (1)

Q1

Given a table of integers, write a SQL query that returns each number alongside the cumulative sum of all values less than or equal to it.

Algorithms & Data StructuresData Modeling
Author's notes

Knew immediately this was a window function thing but second-guessed myself and started writing a self-join first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the cumulative sum should be computed over all values less than or equal to each number, including duplicates. Use a window function with an ORDER BY on the number and a RANGE frame to include all equal values, or a self-join if window functions are unavailable. Then write a clean SQL query that returns each number and its cumulative sum.

Pro tip: Mention that using RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW correctly handles duplicates by including all rows with the same value, which is often a subtle point. Also, note that if the table has duplicate numbers, the cumulative sum for each duplicate should be the same.

1. Clarify requirements and edge cases

Confirm that the cumulative sum includes all values less than or equal to the current number, and that duplicates should be handled by including all equal values. Ask about nulls, negative numbers, and whether the output should be sorted.

2. Choose the appropriate SQL technique

Decide between using a window function (e.g., SUM() OVER (ORDER BY num RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) or a self-join with GROUP BY. Window functions are more efficient and standard in modern SQL.

3. Write the query

Construct the SQL query, ensuring the window frame is correctly specified to include all rows with values <= current value. If using a self-join, join the table to itself on t1.num >= t2.num and group by t1.num.

4. Test with sample data

Mentally or verbally test the query with a small dataset containing duplicates and out-of-order values to verify correctness. Explain how the result changes with duplicates.

5. Discuss performance and alternatives

Mention that window functions are generally more efficient than self-joins, especially for large datasets. If the database doesn't support window functions, describe the self-join approach.

Key Points to Mention

  • Use of window functions (SUM() OVER) with ORDER BY and RANGE frame to handle duplicates correctly.
  • Difference between ROWS and RANGE when dealing with duplicate values.
  • Alternative self-join approach and its performance implications.
  • Handling of NULL values (if any) and whether they should be included or excluded.
  • Importance of sorting the output by the number for readability.
  • Assumption that the table has a column of integers; if not, casting may be needed.

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