Implement a Hash Left Join Between Two Record Lists in Python
Last updated: November 29, 2026
Quick Overview
Without pandas, write a Python function that left joins a list of Facebook post records to a list of Page records on page_id, keeping unmatched posts and producing one row per match.
Meta
November 29, 20260
0
0 solved
Without pandas, write a Python function that left joins a list of Facebook post records to a list of Page records on page_id, keeping unmatched posts and producing one row per match.
Meta interviewers for data-heavy SWE roles sometimes ask you to implement a join yourself to see if you understand what the engine does. They check hashing the build side, NULL key semantics, and duplicate keys on the right side.
What the Interviewer Expects
- Builds a hash index on the right side keyed by join column
- Probes with each left row and emits one row per match
- Emits unmatched left rows once with None for right columns
- Treats None keys as never matching, like SQL NULL
- States O(L + R + output) time
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- Which side should you build the hash table on and why?
- How would you handle a right side that does not fit in memory?
- How would you change this to an inner join or an anti join?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Inputs are lists of dicts. left = posts with post_id, page_id; right = pages with page_id, name. Right keys can repeat (dirty dimension data), and keys can be None. Right-side columns are ...
Approach
Build phase: one pass over right, storing rows in a dict from key to list of rows. Probe phase: for each left row, look up matches; emit one merged row per match, or one row padded with None if no m...