Full Outer Join

HardData EngineeringArraySortingSQL

Description

Given a left and a right table as arrays of [key, value] pairs (keys unique within each), return the full outer join as rows [key, leftValue, rightValue], using null where a side is missing. Order keys by first appearance in the left table, then keys that appear only on the right in their right-table order.

Examples

Input:[[1,10],[2,20]], [[2,200],[3,300]]
Output:[[1,10,null],[2,20,200],[3,null,300]]
Explanation:

Every key from either table produces a row, filling in the value from each side when present and leaving the other empty when not.

Input:[[1,1]], [[1,9]]
Output:[[1,1,9]]
Explanation:

Every key from either table produces a row, filling in the value from each side when present and leaving the other empty when not.

Input:[[1,1],[2,2]], []
Output:[[1,1,null],[2,2,null]]
Explanation:

Every key from either table produces a row, filling in the value from each side when present and leaving the other empty when not.

Constraints

  • 0 ≤ each table ≤ 10⁴
  • keys unique within a table

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.