Write SQL and merge linked lists
Company: Google
Role: Data Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
The technical interview included two coding-style tasks:
1. **SQL analytics task**
You are given three tables:
- `customers(customer_id, customer_name)`
- `orders(order_id, customer_id, order_date, amount)`
- `returns(return_id, order_id, created_at)`
Write a SQL query that returns one row per customer, including customers who have never placed an order. For each customer, report:
- `total_orders`
- `total_amount`
- `latest_order_date`
- `latest_order_amount`
Use a `LEFT JOIN` so customers with no orders still appear. Use a nested query, common table expression, or window function to identify the most recent order for each customer.
2. **List manipulation task**
Given the heads of two singly linked lists whose values are already sorted in non-decreasing order, merge them into one sorted linked list by reusing the existing nodes, and return the head of the merged list.
Quick Answer: This question evaluates SQL analytics skills—covering joins, aggregations and row-level most-recent selection—and fundamental algorithmic competency in in-place merging of sorted singly linked lists.