← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026

Summary

Google data engineer interview with two back-to-back technical problems: a SQL analytics question and a linked list merge. Nothing too exotic but the SQL one had enough edge cases to trip you up if you weren't paying attention.

Questions Asked (4)

Q1

Given a customers table, an orders table, and a returns table, write a SQL query that returns one row per customer with total order count, total amount, latest order date, and the amount of that latest order. Customers with no orders should still appear.

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

This one took longer than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and business definitions (e.g., what constitutes an order, how returns affect total amount). Then, use a LEFT JOIN from customers to orders to ensure all customers appear, and use window functions or subqueries to get the latest order date and its amount. Finally, aggregate order counts and total amounts, handling NULLs appropriately.

Pro tip: Mention that you'd verify whether 'total amount' should be net of returns, and consider performance implications of different approaches (e.g., window functions vs. correlated subqueries) especially for large datasets.

1. Clarify requirements and schema

Ask about the table structures, what 'total amount' means (gross or net of returns), and whether returns should affect order counts. Confirm that customers with no orders should have NULL or zero for aggregates.

2. Ensure all customers are included

Use a LEFT JOIN from customers to orders to retain customers without orders. If returns are involved, consider how to incorporate them without duplicating orders.

3. Compute aggregates and latest order details

Use GROUP BY customer to compute total order count and total amount. For latest order date and amount, use a window function (ROW_NUMBER) or a correlated subquery to identify the most recent order per customer.

4. Handle returns appropriately

If returns affect total amount, subtract returned amounts. Be careful to avoid double-counting orders when joining returns; consider aggregating returns separately or using conditional aggregation.

5. Finalize and validate the query

Write the final SQL, ensuring correct handling of NULLs (e.g., COALESCE for counts and amounts). Test with edge cases like customers with no orders or multiple orders on the same date.

Key Points to Mention

  • Use of LEFT JOIN to include customers with no orders
  • Window functions (e.g., ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC)) to get latest order
  • Handling of returns: whether to subtract from total amount and how to avoid duplication
  • Aggregation with GROUP BY and handling NULLs (e.g., COALESCE for counts and sums)
  • Performance considerations: indexing, avoiding correlated subqueries for large datasets
  • Edge cases: multiple orders on the same date, customers with no orders, returns without matching orders

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

Q2

How would you modify the query to exclude returned orders from the totals?

Data ModelingTechnical Trade-offs
Author's notes

Follow-up to the SQL question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the data model and the definition of a 'returned order' (e.g., status column, separate table). Then propose a modification to the query, such as adding a WHERE clause or a JOIN to exclude those orders, and discuss trade-offs like performance and correctness.

Pro tip: Mention that you would verify the exclusion logic with edge cases (e.g., partially returned orders) and consider using a NOT EXISTS clause for better performance when dealing with large datasets.

1. Clarify the data model

Ask or explain how returned orders are represented: is there a status column, a separate returns table, or a flag? This determines the exclusion method.

2. Identify the exclusion condition

Determine the exact condition that identifies a returned order, such as status = 'returned' or existence in a returns table.

3. Modify the query

Add a WHERE clause to filter out returned orders, or use a LEFT JOIN with a NULL check, or a NOT EXISTS subquery, depending on the schema.

4. Consider performance and correctness

Discuss trade-offs: filtering early vs. late, index usage, and handling edge cases like partial returns or multiple returns per order.

5. Validate and test

Suggest testing the modified query with sample data to ensure returned orders are excluded and totals are correct.

Key Points to Mention

  • Use of WHERE clause with status filter
  • LEFT JOIN with IS NULL check for orders not in returns table
  • NOT EXISTS subquery for anti-join
  • Performance implications of different approaches
  • Handling partial returns or multiple returns
  • Importance of indexing on the filter column

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

Q3

Given the heads of two sorted singly linked lists, merge them into one sorted linked list by reusing the existing nodes rather than creating new ones.

Algorithms & Data Structures
Author's notes

Classic problem, knew it cold.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then propose an iterative two-pointer approach that reuses nodes by adjusting next pointers. Walk through the algorithm step-by-step, emphasizing constant space and linear time, and discuss potential pitfalls like handling empty lists and maintaining the sorted order.

Pro tip: Demonstrate awareness of memory management by explicitly stating that no new nodes are allocated, and mention that the solution is optimal in both time and space. Also, consider discussing how to handle duplicate values or stability if relevant.

1. Clarify and Confirm

Ask clarifying questions about input constraints, edge cases (empty lists, single node), and whether the merged list should be sorted in ascending order. Confirm that reusing nodes means no new node allocation.

2. Outline the Approach

Explain that you will use two pointers, one for each list, and a dummy node to simplify the merging process. Iterate while both pointers are non-null, comparing values and linking the smaller node to the merged list, then advance that pointer.

3. Handle Remaining Nodes

After one list is exhausted, link the remainder of the other list directly to the merged list. This works because the remaining list is already sorted.

4. Analyze Complexity

State that the time complexity is O(n + m) where n and m are the lengths of the lists, and space complexity is O(1) since we only rearrange pointers and use a few variables.

5. Test with Examples

Walk through a simple example, such as merging [1,3,5] and [2,4,6], to verify the algorithm. Also consider edge cases like one list empty or lists with duplicate values.

Key Points to Mention

  • Use of a dummy node to simplify edge cases and avoid special handling for the head of the merged list.
  • Iterative two-pointer technique to compare and link nodes in sorted order.
  • Reusing existing nodes by only modifying next pointers, achieving O(1) space.
  • Time complexity O(n + m) and space complexity O(1).
  • Handling edge cases: empty lists, one list empty, duplicate values.
  • Potential follow-up: recursive solution and its trade-offs (stack space).

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

Q4

How would you extend the linked list merge to handle k sorted lists instead of two?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Answered with a min-heap approach.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by generalizing the two-list merge using a min-heap to efficiently select the smallest current element among k lists. Then analyze the time and space complexity, comparing it to alternative approaches like divide-and-conquer merging. Finally, discuss trade-offs and potential optimizations for different scenarios.

Pro tip: Mention that for unequal list sizes, a divide-and-conquer approach can be more cache-friendly and avoid heap overhead, but the heap is simpler and often preferred in interviews. Also, note that if k is large, the heap size can be a bottleneck, so consider the total number of elements.

1. Clarify the problem

Confirm assumptions: each list is sorted, total elements N, k lists. Ask if k is large or if lists have varying sizes.

2. Propose heap-based solution

Describe using a min-heap of size k to store the current head of each list. Repeatedly extract the minimum, append to result, and insert the next node from that list.

3. Analyze complexity

State time complexity O(N log k) and space O(k) for the heap. Compare with naive sequential merge O(N k) and divide-and-conquer O(N log k) but with different constants.

4. Discuss trade-offs and optimizations

Mention that divide-and-conquer may be better for unequal sizes or when k is very large, and that heap can be optimized using a priority queue of nodes.

5. Handle edge cases

Address empty lists, k=0, k=1, and duplicate values. Also mention stability if needed.

Key Points to Mention

  • Min-heap (priority queue) to efficiently get the smallest element among k lists
  • Time complexity O(N log k) and space O(k)
  • Comparison with divide-and-conquer approach (merge lists in pairs)
  • Trade-offs: heap overhead vs. divide-and-conquer recursion
  • Edge cases: empty lists, k=0, k=1, large k
  • Potential optimizations: using a tournament tree or adjusting heap size

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