PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Write SQL and merge linked lists

Last updated: Apr 22, 2026

Quick Overview

Solve a SQL customer order aggregation task and merge two sorted linked lists. The solution uses CTEs, window functions, LEFT JOINs, COALESCE, latest-order tie handling, optional returned-order filtering, and an O(m+n) dummy-head linked-list merge.

  • medium
  • Google
  • Coding & Algorithms
  • Data Engineer

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: a SQL analytics query and merging two sorted linked lists. ### Constraints & Assumptions - For SQL, return one row per customer, including customers with no orders. - Report `total_orders`, `total_amount`, `latest_order_date`, and `latest_order_amount`. - Use a nested query, CTE, or window function to identify each customer's most recent order. - For linked lists, reuse existing nodes and return the merged head. ### Clarifying Questions to Ask - If a customer has multiple orders on the same latest date, how should ties be handled? - Should returned orders affect total order amount? - Should `total_amount` be `0` or `NULL` for customers with no orders? - Are linked-list values sorted in non-decreasing order? ### Part 1 - Write The SQL Query Given `customers`, `orders`, and `returns`, write a query returning customer-level order metrics and latest order amount. #### What This Part Should Cover - Aggregate orders by customer. - Use `ROW_NUMBER()` or similar to find the latest order per customer. - `LEFT JOIN` from customers so customers without orders remain. - `COALESCE` for zero counts and amounts if desired. ### Part 2 - Merge Two Sorted Linked Lists Given heads of two sorted singly linked lists, merge them into one sorted list by reusing nodes. #### What This Part Should Cover - Dummy head and tail pointer. - Compare current node values and append the smaller node. - Attach the remaining suffix. - Complexity and edge cases. ### What a Strong Answer Covers - Preserves customers with no orders. - Handles latest-order tie assumptions explicitly. - Avoids double-counting from unnecessary joins to returns. - Reuses linked-list nodes without allocating new list nodes. ### Follow-up Questions - How would you exclude returned orders? - How would you handle ties in latest order date? - How would you merge `k` sorted linked lists? - What is the recursive linked-list solution?

Quick Answer: Solve a SQL customer order aggregation task and merge two sorted linked lists. The solution uses CTEs, window functions, LEFT JOINs, COALESCE, latest-order tie handling, optional returned-order filtering, and an O(m+n) dummy-head linked-list merge.

Related Interview Questions

  • Count Rectangle Coverage on a Grid - Google (easy)
  • Deduplicate and Order Batch and Streaming Logs - Google (medium)
  • Count Overlapping Rectangle Updates on a Grid - Google (hard)
  • Find A Threshold-Limited Path With Minimum Required Safety - Google (medium)
  • Filter Repeated Robot Status Messages - Google (medium)
|Home/Coding & Algorithms/Google

Write SQL and merge linked lists

Google logo
Google
Mar 9, 2025, 12:00 AM
mediumData EngineerTechnical ScreenCoding & Algorithms
3
0

The technical interview included two coding-style tasks: a SQL analytics query and merging two sorted linked lists.

Constraints & Assumptions

  • For SQL, return one row per customer, including customers with no orders.
  • Report total_orders , total_amount , latest_order_date , and latest_order_amount .
  • Use a nested query, CTE, or window function to identify each customer's most recent order.
  • For linked lists, reuse existing nodes and return the merged head.

Clarifying Questions to Ask Guidance

  • If a customer has multiple orders on the same latest date, how should ties be handled?
  • Should returned orders affect total order amount?
  • Should total_amount be 0 or NULL for customers with no orders?
  • Are linked-list values sorted in non-decreasing order?

Part 1 - Write The SQL Query

Given customers, orders, and returns, write a query returning customer-level order metrics and latest order amount.

What This Part Should Cover Guidance

  • Aggregate orders by customer.
  • Use ROW_NUMBER() or similar to find the latest order per customer.
  • LEFT JOIN from customers so customers without orders remain.
  • COALESCE for zero counts and amounts if desired.

Part 2 - Merge Two Sorted Linked Lists

Given heads of two sorted singly linked lists, merge them into one sorted list by reusing nodes.

What This Part Should Cover Guidance

  • Dummy head and tail pointer.
  • Compare current node values and append the smaller node.
  • Attach the remaining suffix.
  • Complexity and edge cases.

What a Strong Answer Covers Guidance

  • Preserves customers with no orders.
  • Handles latest-order tie assumptions explicitly.
  • Avoids double-counting from unnecessary joins to returns.
  • Reuses linked-list nodes without allocating new list nodes.

Follow-up Questions Guidance

  • How would you exclude returned orders?
  • How would you handle ties in latest order date?
  • How would you merge k sorted linked lists?
  • What is the recursive linked-list solution?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Data Engineer•Google Data Engineer•Google Coding & Algorithms•Data Engineer Coding & Algorithms
PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.