Normalize Loan Merchants to Root Businesses
Updated
Problem statement
A lender has loans, and each loan comes with a merchant name. The lender also has a fixed business hierarchy, given as two lists of the same length: parents[i] is the direct parent business of children[i].
For every name in loanMerchants, follow the parent links up until you reach a root business, which is a name with no parent. Return the root business name for each loan merchant, in the same order as the loans.
If a loan merchant is already a root business, its answer is its own name.
Function
normalizeLoanMerchants(parents: String[], children: String[], loanMerchants: String[]) → String[]Examples
Example 1
parents = ["Northstar","Northstar","FreshCo"]children = ["FreshCo","Spark","Market"]loanMerchants = ["Market","Spark","Northstar"]return = ["Northstar","Northstar","Northstar"]Market belongs to FreshCo, which belongs to Northstar. Spark also belongs to Northstar. Northstar has no parent, so it is its own root. Every answer is Northstar.
Example 2
parents = ["Atlas","Atlas","Beta"]children = ["Beta","Gamma","Delta"]loanMerchants = ["Delta","Gamma","Atlas","Beta"]return = ["Atlas","Atlas","Atlas","Atlas"]Delta belongs to Beta, which belongs to Atlas. Gamma and Beta belong to Atlas directly, and Atlas has no parent. So every answer is Atlas.
Example 3
parents = ["A","B"]children = ["A1","B1"]loanMerchants = ["B1","A1","B"]return = ["B","A","B"]There are two separate hierarchies, with roots A and B. B1 goes up to B, A1 goes up to A, and B is already a root. In loan order, the answers are B, A, B.
Constraints
0 <= parents.length == children.length <= 100000.1 <= loanMerchants.length <= 100000.- Names are nonempty, case-sensitive strings of at most 100 characters.
- Each child has at most one parent, and the hierarchy has no cycles.
- Every loan merchant appears in the hierarchy or is a root business.
More Affirm interview questions
- Propagating Fraud DetectorPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Cross-Day User Trust ScoresPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count Distinct Underwriting PII ValuesPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- High-Card Pot GamePHONE SCREEN · Seen Sep 2026
- Assign Sequential Loan IdentifiersPHONE SCREEN · Seen Sep 2026
- Redeemable Promotion OffersPHONE SCREEN · Seen Aug 2026
- Group Loans by Top-Level Parent CompanyPHONE SCREEN · Seen Aug 2026
- Group Transactions by HourONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Predicate Expression Tree EvaluatorMongoDB · PHONE SCREENMongoDB interview questions
- Lowest Common Manager for Employee GroupsAmazon · PHONE SCREEN
- Lowest Common Manager for Employee GroupsGoogle · PHONE SCREENGoogle interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- House Robber IIIOkta · PHONE SCREENOkta interview questions
- House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
- Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
- House Robber IIIVisa · PHONE SCREENVisa interview questions