Google | Phone Screen | L4 | Inner and Outer Join of two tables
Anonymous User
747

Do inner join of two tables in less than O(m*n) runtime:

Table1:

A | B


1 | 3
2 | 6

Table2:

B | C


6 | 8
5 | 3

Then table1.inner_join(table2, “B”) should return a table as follows since B = 6 in both tables:

A | B | C


2 | 6 | 8

Input:
columnNameForTable1: [A, B]
rowsListForTable1: [[1, 2], [3, 6]]
columnNameForTable2: [B, C]
rowsListForTable2: [[6, 5], [8, 3]]

Output should be:
columnNameForTable: [A, B, C]
rowsListForTable: [[2], [6] ,[8]]

Was not able to solve this.
Can someone please help with solving this?


Outer Join: No time constraints

Example 1:

Table1:
A | B


1 | 3
2 | 6

Table2:
B | C


6 | 8
5 | 3

Then table1.outer_join(table2, “B”) should return a table as follows:

A | B | C


1 | 3 | 0
2 | 6 | 8
0 | 5 | 3

Input:
columnNameForTable1: [A, B]
rowsListForTable1: [[1, 2], [3, 6]]
columnNameForTable2: [B, C]
rowsListForTable2: [[6, 5], [8, 3]]

Output should be:
columnNameForTable: [A, B, C]
rowsListForTable: [[1,2,0], [3,6,5] ,[0,8,3]]

Comments (3)