Day 16 — Merge Two Sorted Lists
Coding problem
| Problem | Merge Two Sorted Lists |
| LeetCode ID(s) | LeetCode #21 |
| Difficulty | Easy |
| Pattern | Linked List Merge |
| Company tags | Meta |
| Suggested time | 10m |
Solution outline (coding)
Focus on the Linked List Merge pattern. Start by writing out a few examples by hand, then identify the invariant you must maintain (e.g., prefix sums, window bounds, visited set, heap ordering). Aim for an implementation you can explain in under a minute, including time and space complexity.
Show Python solution
# Solution template based on the main pattern for this day.
# Replace this with your final, production-ready solution as you practice.SQL question
orders_a(order_id, user_id, created_at) and orders_b(order_id, user_id, created_at). BigQuery: merge these two sorted streams into a single time-ordered view per user, flagging duplicates and conflicting records.
How to approach (SQL)
Break the prompt into steps:
- Identify source tables, required joins, and filters (especially on time partitions).
- Decide where you need GROUP BY vs. window functions (e.g.,
ROW_NUMBER,SUM() OVER,COUNT() OVER). - For BigQuery, think about partitioning and clustering to avoid unnecessary full scans.
- Write the query in stages (CTEs) so each step is easy to debug and reason about. Finish by checking edge cases: nulls, late events, duplicated keys, and extreme values.