Code RoomSort-merge inner join
HardPrep Room Coding #253

Sort-merge inner join

CodingDatabases & SQLAlgorithms & data structuresSenior–Staff~35 min

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.

0:00 of about 35 min
InputExpectedGot
[[[1,"a"],[2,"b"],[2,"c"]],[[2,"x"],[2,"y"],[3,"z"]]][["b","x"],["b","y"],["c","x"],["c","y"]]not run yetsample