Join tables to map userId to name
KaratSoftware Engineer · Technical ScreenLast updated
This question evaluates a candidate's skills in relational data joining, data integration, and numeric reconciliation for mapping userId to customerName across multiple tables.
Problem
You are given three tables represented as 2D string arrays (each row is a record, no headers). You need to produce a mapping from userId → customerName by matching and joining information across tables.
Table 1: customers
Each row: [customerName, email, productName, quantity]
quantityis an integer in string form.- Assumption: each customer buys only one type of product (i.e., one
productNameper customer).
Table 2: orders
Each row: [userId, email, orderTotal]
orderTotalis a number in string form (integer or decimal).emailmay be null (or an empty string, depending on how the input is represented).
Table 3: products
Each row: [productName, unitPrice]
unitPriceis a number in string form.
Matching / Join requirement
For each order record, identify which customer placed it, then output userId -> customerName.
Use these matching rules:
- If
orders.emailis present (non-null/non-empty), match the customer by email. - If
orders.emailis missing, match by using the fact that:
orderTotal = quantity * unitPricefor the customer’s purchased product.- Use
customers.productNamejoined toproducts.productNameto getunitPrice.
Output
Return a mapping/dictionary from userId to customerName for all orders.
Assumptions / Edge cases
- If multiple customers could match an order (e.g., same computed total), specify and implement a deterministic tie-breaker (e.g., pick lexicographically smallest name) or return all candidates—clarify with the interviewer.
- Assume inputs are well-formed aside from possible null/empty emails.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.