Join tables to map userId to name
Company: Karat
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's skills in relational data joining, data integration, and numeric reconciliation for mapping userId to customerName across multiple tables.
Constraints
- 1 <= len(customers), len(orders), len(products) <= 100000
- quantity is an integer string that fits in 32-bit signed range
- unitPrice and orderTotal are valid numeric strings (integer or decimal)
- orders.email may be None or ""
- If multiple customers match, choose the lexicographically smallest customerName
- Inputs are well-formed so that each order can be matched by email or by total
Examples
Input: ([['Alice','a@x.com','Book','2'],['Bob','b@x.com','Pen','5']], [['u1','a@x.com','20'],['u2',None,'10']], [['Book','10'],['Pen','2']])
Expected Output: {'u1': 'Alice', 'u2': 'Bob'}
Explanation: u1 matches by email -> Alice. u2 has no email, total 10 matches Bob because 5*2=10.
Input: ([['Amy','amy@mail','Widget','1'],['Zoe','zoe@mail','Widget','1'],['Bob','bob@mail','Gadget','2']], [['1',None,'9.99'],['2','','9.99'],['3',None,'9.990'],['4','bob@mail','10']], [['Widget','9.99'],['Gadget','5']])
Expected Output: {'1': 'Amy', '2': 'Amy', '3': 'Amy', '4': 'Bob'}
Explanation: Orders 1-3 match by total 9.99; both Amy and Zoe match, pick lexicographically smallest -> Amy. Order 4 matches by email -> Bob.