Code Room
CodingHardcod-g1087
Subject Query merge joinLevel Senior–Staff~35 minCommon in Databases & SQL · Algorithms & data structures interviewsIndustries Software development, Technology

Question

Implement a sort-merge inner join on two tables already sorted by their join key. Each table is a list of [key, value] pairs sorted ascending by key (keys are ints, duplicates allowed within a table). Produce all matching pairs [left_value, right_value] for rows where left.key == right.key, handling the many-to-many case (the cartesian product within each equal-key block). Emit results in ascending key order; within a key, pair each left value with each right value preserving the input order of both. Return the list of [left_value, right_value] pairs.

Implement
merge_join(left: list[list], right: list[list]) → list[list]
Examples
in[[[1,"a"],[2,"b"],[2,"c"]],[[2,"x"],[2,"y"],[3,"z"]]]out[["b","x"],["b","y"],["c","x"],["c","y"]]
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.