Inner Join

MediumData EngineeringArraySortingSQL

Description

Given two tables as arrays of [key, value] pairs (keys are unique within each table), return the inner join: for every key present in both tables, a row [key, leftValue, rightValue]. Order the result by the keys’ first appearance in the left table.

Examples

Input:[[1,10],[2,20],[3,30]], [[2,200],[3,300],[4,400]]
Output:[[2,20,200],[3,30,300]]
Explanation:

Only keys present in both tables survive, each paired with its left and right value, ordered by where the key first appears on the left.

Input:[[1,5]], [[1,50]]
Output:[[1,5,50]]
Explanation:

Only keys present in both tables survive, each paired with its left and right value, ordered by where the key first appears on the left.

Input:[[1,10],[2,20]], [[3,30]]
Output:[]
Explanation:

Only keys present in both tables survive, each paired with its left and right value, ordered by where the key first appears on the left.

Constraints

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

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.