Problem · Hash Table

Record Linkage Part 1 - Directly Linked Records

Learn this problem
MediumStripe logoStripeFULLTIMEPHONE SCREEN
See Stripe hiring insights

Problem statement

You are given user records and must decide which records are linked to a target record using weighted field similarity.

Inputs:

  • rows: a String[] where each entry is "id,name,email,company" (id is an integer).
  • weights: a String[] where each entry is "field,weight" for a field in {name, email, company}; the weights sum to 1.
  • threshold: a similarity cutoff.
  • targetId: the id of the target record.

The similarity between two records is the weighted sum over the fields of per-field equality (contribute the field's weight when the two records have the same value for that field, otherwise 0). Two records are linked when their similarity is >= threshold.

Return the ids of all records directly linked to the record with targetId (excluding the target itself), as an int[] sorted in ascending order.

Function

findLinkedRecords(rows: String[], weights: String[], threshold: float, targetId: int) → int[]

Examples

Example 1

rows = ["1,Alice,alice@gmail.com,Stripe", "2,Alicia,alice@gmail.com,Stripe", "3,Alice,alice@yahoo.com,Google", "4,Bob,bob@gmail.com,Stripe"]weights = ["name,0.2", "email,0.5", "company,0.3"]threshold = 0.5targetId = 1return = [2]
Compare each record to record 1 (Alice, alice@gmail.com, Stripe). Record 2: name differs (0), email same (+0.5), company same (+0.3) = 0.8 >= 0.5 -> linked. Record 3: name same (+0.2), email differs, company differs = 0.2 < 0.5 -> not linked. Record 4: name differs, email differs, company same (+0.3) = 0.3 < 0.5 -> not linked. Only record 2 is directly linked.

Example 2

rows = ["1,Alice,alice@gmail.com,Stripe", "2,Alicia,alice@gmail.com,Stripe", "3,Alice,alice@yahoo.com,Google", "4,Bob,bob@gmail.com,Stripe"]weights = ["name,0.2", "email,0.5", "company,0.3"]threshold = 0.5targetId = 4return = []
Record 4 is Bob, bob@gmail.com, Stripe. Against record 1: only company matches (0.3). Against record 2: only company matches (0.3). Against record 3: nothing matches (0). All below the 0.5 threshold, so record 4 has no direct links.

Constraints

  • Each row is "id,name,email,company" with an integer id.
  • Each weight entry is "field,weight" over {name, email, company}; weights sum to 1.
  • Similarity = sum of weights of fields whose values are equal between the two records.
  • Two records are linked when similarity >= threshold.
  • Return the ascending-sorted int[] of ids directly linked to targetId, excluding the target.

More Stripe problems

drafts saved locally
public int[] findLinkedRecords(String[] rows, String[] weights, float threshold, int targetId) {
  // write your code here
}
rows["1,Alice,alice@gmail.com,Stripe", "2,Alicia,alice@gmail.com,Stripe", "3,Alice,alice@yahoo.com,Google", "4,Bob,bob@gmail.com,Stripe"]
weights["name,0.2", "email,0.5", "company,0.3"]
threshold0.5
targetId1
expected[2]
checking account