FastPrepRank Linked Merchants by Weighted Shared Attributes
Problems/Rank Linked Merchants by Weighted Shared Attributes

Rank Linked Merchants by Weighted Shared Attributes

Stripe logoStripe● MediumFULLTIMENEW GRADINTERNPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The judged weighted-linking exercise retains an approximately 80% match to the earlier source. Its flat record/weight adapters, positive-score cutoff, ranked merchantId|score output and bounds are practice conventions, not details confirmed by the newer report. A later two-part recollection provides native dictionaries, case-sensitive corresponding-field matches, caller-supplied weights and a threshold, with ID-only output. The optional variation preserves those details separately without replacing the judged ranking task. Threshold equality, output ordering, missing-field behavior and any third part were not specified.

Special thanks: 🌷 A special thank you to a lovely, amazing fren for sharing a two-part merchant-matching interview variation from October 20, 2026 and clarifying its input and output details! ( ˘͈ ᵕ ˘͈♡) 🩵

You are given merchant records, attribute weights, and a target merchant ID.

Each row in merchants starts with a unique merchant ID and then contains alternating attribute names and values: [merchantId, name1, value1, name2, value2, ...]. Attribute names are unique within one row.

Each entry in attributeWeights has the form attributeName|weight. An attribute contributes its weight to another merchant's link score when that merchant and the target have exactly the same attribute name and value. Attributes without a supplied weight contribute zero.

Exclude the target. A different merchant is linked when its score is positive. Return every linked merchant as merchantId|score, ordered by descending score and then by ascending merchant ID.

When every supplied weight is 1, the result contains exactly the merchants that share at least one weighted attribute with the target.

Reported two-part dictionary variation

This optional interview variation is separate from the ranked-output practice contract above. Merchant records were provided as native dictionaries in a list, with fields such as merchantID, companyName, email, and phone. A target merchant ID identifies the merchant to compare against the other records.

[{"merchantID": "m1", "companyName": "name", "email": "email", "phone": "pn1"}]
  1. In Part 1, a merchant is directly connected to the target when at least one corresponding attribute matches exactly. Matching is case-sensitive.
  2. In Part 2, the caller also supplies a dictionary mapping companyName, email, and phone to integer weights, together with a score threshold. Exact matches of the corresponding fields determine the weighted shared-attribute score, which is checked against that threshold.

The reported result is a list of matching IDs, such as ["m2", "m6", "m8"], rather than scored strings. The recollection does not establish whether equality at the threshold qualifies, the required output order, or missing-field behavior; clarify those details before implementing that variation. It does not add a two-hop requirement or a third part. The judged submission for this page still uses rankLinkedMerchants and the ranked merchantId|score results defined above.

Function

rankLinkedMerchants(merchants: String[][], attributeWeights: String[], targetMerchantId: String) → String[]

Examples

Example 1

merchants = [["m1","email","a@x","country","US","phone","111"],["m2","email","a@x","country","US","phone","999"],["m3","email","z@x","country","US","phone","111"],["m4","email","a@x","country","CA","phone","111"],["m5","email","z@x","country","CA"]]attributeWeights = ["email|5","phone|3","country|2"]targetMerchantId = "m1"return = ["m4|8","m2|7","m3|5"]

m4 matches email and phone for score 8; m2 matches email and country for 7; m3 matches phone and country for 5. m5 scores zero.

Example 2

merchants = [["target","email","root@x","note","same"],["b","email","root@x"],["a","email","root@x"],["c","note","same"]]attributeWeights = ["email|4","note|0"]targetMerchantId = "target"return = ["a|4","b|4"]

a and b tie and are ordered by ID. Although c matches note, that attribute has weight zero, so c is not linked.

Example 3

merchants = [["solo","region","west"]]attributeWeights = ["region|10"]targetMerchantId = "solo"return = []

The target is excluded and there are no other merchants.

Constraints

  • 1 <= merchants.length <= 100000.
  • Every merchant row contains a unique nonempty ID followed by at most 20 attribute-name/value pairs.
  • Merchant IDs, attribute names, and attribute values are printable ASCII strings of length at most 100 and contain no pipe character.
  • 1 <= attributeWeights.length <= 20, and every weighted attribute name appears at most once.
  • Every weight is an integer from 0 through 1000000.
  • targetMerchantId identifies exactly one merchant.

More Stripe problems

  • Portfolio Valuation, Part 1PHONE SCREEN · Seen Nov 2026
  • Chat Billing CalculationOA · Seen Nov 2026
  • Deployment Window SchedulerOA · Seen Nov 2026
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String[] rankLinkedMerchants(String[][] merchants, String[] attributeWeights, String targetMerchantId) {
        // Write your code here.
    }
}
Checking account…