Code Room
CodingHardcod-g1077
Subject Database joinLevel Mid–Senior~30 minCommon in Databases & SQL · Algorithms & data structures interviewsIndustries Software development, Technology

Question

Implement a relational join of two tables given as lists of dicts. Join 'left' and 'right' on the column name 'key' (present in both). For 'inner' join, emit one merged row per matching pair; for 'left' join, also emit left rows with no match, filling right-only columns with the string '__NULL__'. Merged rows contain the left row's fields plus the right row's fields, with right values winning on any shared non-key column name. Preserve left-table order, and for a given left row preserve right-table order of its matches. Return the list of merged dicts.

Implement
join_tables(left: list[dict], right: list[dict], how: str) → list[dict]
Examples
in[[{"key":1,"name":"a"},{"key":2,"name":"b"}],[{"key":1,"city":"NY"},{"key":1,"city":"LA"}],"inner"]out[{"key":1,"city":"NY","name":"a"},{"key":1,"city":"LA","name":"a"}]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.