FastPrepMerchant Matching, Parts 1–2: Shared Fields and Weighted Thresholds
Problems/Merchant Matching, Parts 1–2: Shared Fields and Weighted Thresholds

Merchant Matching, Parts 1–2: Shared Fields and Weighted Thresholds

Stripe logoStripe● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Stripe intern phone screen. Our version is about 90% the same as the reported two-part exercise. Dictionary fields, weights and a threshold that the caller gives, exact matching that respects case, and a list of IDs as output all come from the source. The report does not give how scores are added up, whether a score equal to the threshold counts, the order of the output, checks on input or number limits. We chose those.

Special thanks: 🌷 A special thank you to a lovely, amazing fren for sharing the two-part merchant-matching question from October 20, 2026 and clarifying its dictionary inputs, matching rules and ID-list output! ( ˘͈ ᵕ ˘͈♡) 🩵

Given a list of merchant dictionaries and a target merchant ID, return a list of matching merchant IDs. Each dictionary has the fields merchantID, companyName, email, and phone. The weight dictionary has one integer weight for each of companyName, email, and phone.

Part 1: Any shared field

When part = 1, include a merchant if at least one of its companyName, email or phone values exactly matches the same field of the target. Ignore the weights and threshold in this part.

Part 2: Weighted shared fields

When part = 2, use the caller-provided weight dictionary and threshold to decide which merchants to include. Equality is case-sensitive and field-specific. Do not trim, lowercase, or compare a value against a different field. The merchant ID is an identifier, not a matching attribute.

A Part 2 score is the sum of the weights of all matching corresponding fields, and a merchant qualifies when its score is greater than or equal to threshold.

Compare every merchant directly with the target. Do not add merchants through another merchant or through chains of links.

Leave the target out. Return each matching ID once, in the same order as the merchants in the input.

How the input arrives

The interview uses dictionaries. Here they come as JSON text: merchantsJson encodes the list of objects, and attributeWeightsJson encodes the weight object. Decode them before matching. The part parameter selects one of the two stages; it is either 1 or 2. Return only IDs, not scores or merchant objects.

merchantsJson decodes to:
[{"merchantID":"m1","companyName":"Acme","email":"hello@acme","phone":"111"},
 {"merchantID":"m2","companyName":"Other","email":"hello@acme","phone":"222"}]

attributeWeightsJson decodes to:
{"companyName":3,"email":5,"phone":2}

The Java and C++ reference solutions include a small JSON reader built only on the standard library. The matching logic is separate.

Ready-to-use dictionary decoding

Reading the JSON is not part of the interview task. The Java starter already includes a decoder. For C++, copy the full code below into the editor. Both versions give you decoded dictionaries before the matching step. In Python use json.loads, in JavaScript use JSON.parse, and in Go use encoding/json. Write the matching logic rather than a parser.

Java starter code

// JSON adapter: valid arrays, objects, strings and numbers only.
// The merchant-matching algorithm starts in matchMerchantIds below.
private static class JsonReader {
    final String text;
    int pos;
    JsonReader(String text) { this.text = text; }
    void space() { while (pos < text.length() && Character.isWhitespace(text.charAt(pos))) pos++; }
    String string() {
        pos++;
        StringBuilder out = new StringBuilder();
        while (text.charAt(pos) != '"') {
            char c = text.charAt(pos++);
            if (c == '\\') {
                c = text.charAt(pos++);
                if (c == 'u') {
                    c = (char) Integer.parseInt(text.substring(pos, pos + 4), 16);
                    pos += 4;
                } else if (c == 'b') c = '\b';
                else if (c == 'f') c = '\f';
                else if (c == 'n') c = '\n';
                else if (c == 'r') c = '\r';
                else if (c == 't') c = '\t';
            }
            out.append(c);
        }
        pos++;
        return out.toString();
    }
    Object read() {
        space();
        char c = text.charAt(pos);
        if (c == '"') return string();
        if (c == '[') {
            pos++;
            java.util.List<Object> out = new java.util.ArrayList<>();
            space();
            if (text.charAt(pos) == ']') { pos++; return out; }
            while (true) {
                out.add(read()); space();
                if (text.charAt(pos++) == ']') return out;
            }
        }
        if (c == '{') {
            pos++;
            java.util.Map<String,Object> out = new java.util.LinkedHashMap<>();
            space();
            if (text.charAt(pos) == '}') { pos++; return out; }
            while (true) {
                space(); String key = string(); space(); pos++;
                out.put(key, read()); space();
                if (text.charAt(pos++) == '}') return out;
            }
        }
        int start = pos;
        while (pos < text.length() && ",]} \t\r\n".indexOf(text.charAt(pos)) < 0) pos++;
        return Double.valueOf(text.substring(start, pos));
    }
}

public String[] matchMerchantIds(String merchantsJson, String targetMerchantId, String attributeWeightsJson, int threshold, int part) {
    java.util.List<?> merchants = (java.util.List<?>) new JsonReader(merchantsJson).read();
    java.util.Map<?,?> weights = (java.util.Map<?,?>) new JsonReader(attributeWeightsJson).read();
    // write your code here: merchants and weights are decoded dictionaries.
}

C++ starter code

#include <string>
#include <vector>
#include <map>
#include <cctype>
using namespace std;

class Solution {
    // JSON adapter for the two documented flat dictionary schemas.
    struct JsonReader {
        const string &text;
        size_t pos = 0;
        JsonReader(const string &text) : text(text) {}
        void space() { while (pos < text.size() && isspace((unsigned char)text[pos])) ++pos; }
        string quoted() {
            ++pos;
            string out;
            while (text[pos] != '"') {
                char c = text[pos++];
                if (c == '\\') {
                    c = text[pos++];
                    if (c == 'u') { c = (char)stoi(text.substr(pos, 4), nullptr, 16); pos += 4; }
                    else if (c == 'b') c = '\b';
                    else if (c == 'f') c = '\f';
                    else if (c == 'n') c = '\n';
                    else if (c == 'r') c = '\r';
                    else if (c == 't') c = '\t';
                }
                out += c;
            }
            ++pos;
            return out;
        }
        map<string,string> object() {
            space(); ++pos;
            map<string,string> out;
            space();
            if (text[pos] == '}') { ++pos; return out; }
            while (true) {
                space(); string key = quoted(); space(); ++pos; space();
                string value;
                if (text[pos] == '"') value = quoted();
                else {
                    size_t start = pos;
                    while (pos < text.size() && text[pos] != ',' && text[pos] != '}' && !isspace((unsigned char)text[pos])) ++pos;
                    value = text.substr(start, pos - start);
                }
                out[key] = value; space();
                if (text[pos++] == '}') return out;
            }
        }
        vector<map<string,string>> array() {
            space(); ++pos;
            vector<map<string,string>> out;
            space();
            if (text[pos] == ']') { ++pos; return out; }
            while (true) {
                out.push_back(object()); space();
                if (text[pos++] == ']') return out;
            }
        }
    };
public:
    vector<string> matchMerchantIds(string merchantsJson, string targetMerchantId, string attributeWeightsJson, int threshold, int part) {
        auto merchants = JsonReader(merchantsJson).array();
        auto weights = JsonReader(attributeWeightsJson).object();
        // write your code here: merchants and weights are decoded dictionaries.
        return {};
    }
};

Function

matchMerchantIds(merchantsJson: String, targetMerchantId: String, attributeWeightsJson: String, threshold: int, part: int) → String[]

Examples

Example 1

merchantsJson = "[{\"merchantID\":\"m8\",\"companyName\":\"Acme\",\"email\":\"x\",\"phone\":\"q\"},{\"merchantID\":\"m1\",\"companyName\":\"Acme\",\"email\":\"e\",\"phone\":\"p\"},{\"merchantID\":\"m2\",\"companyName\":\"Beta\",\"email\":\"e\",\"phone\":\"r\"},{\"merchantID\":\"m6\",\"companyName\":\"Acme\",\"email\":\"e\",\"phone\":\"s\"},{\"merchantID\":\"m4\",\"companyName\":\"Delta\",\"email\":\"y\",\"phone\":\"p\"},{\"merchantID\":\"m3\",\"companyName\":\"Beta\",\"email\":\"y\",\"phone\":\"r\"}]"targetMerchantId = "m1"attributeWeightsJson = "{\"companyName\":3,\"email\":5,\"phone\":2}"threshold = 5part = 1return = ["m8","m2","m6","m4"]

Part 1 asks only whether at least one field equals the target's field. m8 matches companyName, m2 matches email, m6 matches both, and m4 matches phone. m3 shares no field with the target, and m1 is the target, so both are left out. Weights and threshold do not matter in Part 1. In input order the answer is ["m8","m2","m6","m4"].

Example 2

merchantsJson = "[{\"merchantID\":\"m8\",\"companyName\":\"Acme\",\"email\":\"x\",\"phone\":\"q\"},{\"merchantID\":\"m1\",\"companyName\":\"Acme\",\"email\":\"e\",\"phone\":\"p\"},{\"merchantID\":\"m2\",\"companyName\":\"Beta\",\"email\":\"e\",\"phone\":\"r\"},{\"merchantID\":\"m6\",\"companyName\":\"Acme\",\"email\":\"e\",\"phone\":\"s\"},{\"merchantID\":\"m4\",\"companyName\":\"Delta\",\"email\":\"y\",\"phone\":\"p\"},{\"merchantID\":\"m3\",\"companyName\":\"Beta\",\"email\":\"y\",\"phone\":\"r\"}]"targetMerchantId = "m1"attributeWeightsJson = "{\"companyName\":3,\"email\":5,\"phone\":2}"threshold = 5part = 2return = ["m2","m6"]

In input order, the non-target scores are m8: 3, m2: 5, m6: 8, m4: 2, and m3: 0. The inclusive threshold is 5, so return ["m2","m6"]. This is an ID filter, not descending-score ranking.

Example 3

merchantsJson = "[{\"merchantID\":\"m8\",\"companyName\":\"Acme\",\"email\":\"x\",\"phone\":\"q\"},{\"merchantID\":\"m1\",\"companyName\":\"Acme\",\"email\":\"e\",\"phone\":\"p\"},{\"merchantID\":\"m2\",\"companyName\":\"Beta\",\"email\":\"e\",\"phone\":\"r\"},{\"merchantID\":\"m6\",\"companyName\":\"Acme\",\"email\":\"e\",\"phone\":\"s\"},{\"merchantID\":\"m4\",\"companyName\":\"Delta\",\"email\":\"y\",\"phone\":\"p\"},{\"merchantID\":\"m3\",\"companyName\":\"Beta\",\"email\":\"y\",\"phone\":\"r\"}]"targetMerchantId = "m1"attributeWeightsJson = "{\"companyName\":3,\"email\":5,\"phone\":2}"threshold = 9part = 2return = []

The largest non-target score is 8 for m6, below the threshold 9. The target itself is excluded, so the result is an empty list.

Constraints

  • For this exercise, assume all JSON is valid, object keys are unique, every merchant has exactly merchantID, companyName, email and phone, merchant IDs are unique, the target exists exactly once, and weights has exactly companyName, email and phone.
  • For this exercise, assume there are 1 to 10^4 merchants; all decoded IDs and field values have 1 to 64 printable ASCII characters; weights are integers from 0 to 10^6; and threshold is an integer from 1 to 3 * 10^6.
  • For this exercise, assume merchantsJson has 2 to 20000000 characters, attributeWeightsJson has 2 to 2000 characters, and targetMerchantId has 1 to 64 characters.
  • part is an integer from 1 to 2.
  • JSON string field values may use escapes and object keys may appear in any order. The decoded printable ASCII range is U+0020 through U+007E. JSON numeric spellings must represent integral weight values within the stated bounds.

More Stripe Phone Screen questions

  • Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
  • Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Nov 2026
  • Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
  • Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
  • Portfolio Valuation, Part 1PHONE SCREEN · Seen Nov 2026
  • Account Roles With Parent-User InheritancePHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Flat Records to a Hierarchical TreeAddepar · PHONE SCREEN
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Count Repeat Customers Across DatesAmazon · PHONE SCREEN
  • Flat Comments to a Nested TreeByteDance · PHONE SCREENByteDance interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Invalid Transactions in Time OrderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Product Total With the Cheapest PromotionInstacart · ONSITE INTERVIEWInstacart interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions

Interview reports that mention this question

  • Stripe SWE Intern Linked Merchants Team Screen: 1 Experience

Stripe interview experiences

  • Stripe New Grad SWE OA and Phone Screen: 2 Experiences
  • Stripe Experienced SWE OA and Onsite Questions: 3 Experiences
  • Stripe OA: What It Tests (2026)
  • Stripe SWE Onsite over Two Days: 1 Experience
  • Stripe New Grad SWE Phone Screen and Onsite: 2 Experiences
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    // JSON adapter: valid arrays, objects, strings and numbers only.
    // The merchant-matching algorithm starts in matchMerchantIds below.
    private static class JsonReader {
        final String text;
        int pos;
        JsonReader(String text) { this.text = text; }
        void space() { while (pos < text.length() && Character.isWhitespace(text.charAt(pos))) pos++; }
        String string() {
            pos++;
            StringBuilder out = new StringBuilder();
            while (text.charAt(pos) != '"') {
                char c = text.charAt(pos++);
                if (c == '\\') {
                    c = text.charAt(pos++);
                    if (c == 'u') {
                        c = (char) Integer.parseInt(text.substring(pos, pos + 4), 16);
                        pos += 4;
                    } else if (c == 'b') c = '\b';
                    else if (c == 'f') c = '\f';
                    else if (c == 'n') c = '\n';
                    else if (c == 'r') c = '\r';
                    else if (c == 't') c = '\t';
                }
                out.append(c);
            }
            pos++;
            return out.toString();
        }
        Object read() {
            space();
            char c = text.charAt(pos);
            if (c == '"') return string();
            if (c == '[') {
                pos++;
                java.util.List<Object> out = new java.util.ArrayList<>();
                space();
                if (text.charAt(pos) == ']') { pos++; return out; }
                while (true) {
                    out.add(read()); space();
                    if (text.charAt(pos++) == ']') return out;
                }
            }
            if (c == '{') {
                pos++;
                java.util.Map<String,Object> out = new java.util.LinkedHashMap<>();
                space();
                if (text.charAt(pos) == '}') { pos++; return out; }
                while (true) {
                    space(); String key = string(); space(); pos++;
                    out.put(key, read()); space();
                    if (text.charAt(pos++) == '}') return out;
                }
            }
            int start = pos;
            while (pos < text.length() && ",]} \t\r\n".indexOf(text.charAt(pos)) < 0) pos++;
            return Double.valueOf(text.substring(start, pos));
        }
    }

    public String[] matchMerchantIds(String merchantsJson, String targetMerchantId, String attributeWeightsJson, int threshold, int part) {
        java.util.List<?> merchants = (java.util.List<?>) new JsonReader(merchantsJson).read();
        java.util.Map<?,?> weights = (java.util.Map<?,?>) new JsonReader(attributeWeightsJson).read();
        // write your code here: merchants and weights are decoded dictionaries.
    }
}

Not a valid String

Checking account…