Reported September 2026
Affirmhash table

Normalize Loan Merchants to Root Businesses

Reported by candidates from Affirm's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Affirm OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on Affirm's merchant normalization question is walking the parent chain from scratch for every loan. Affirm candidates reported this OA in September 2026, and the input goes up to 100000 entries, so a naive climb can blow up on a deep hierarchy. It's a tree and forest problem dressed up as string lookups. Build a child-to-parent map, find each root, and cache the answers. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you a working solution in real time as a safety net.

The problem

A lender receives loans associated with merchant names. The lender also has a fixed business hierarchy represented by parallel arrays: parents[i] is the direct parent business of children[i].
For every value in loanMerchants, follow parent links until you reach a root business: a name that has no parent. Return the root business name for each loan merchant in the original loan order.
A root business used directly as a loan merchant resolves to itself.

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, and the root merchant resolves to itself.
Example 2
parents = ["Atlas","Atlas","Beta"]
children = ["Beta","Gamma","Delta"]
loanMerchants = ["Delta","Gamma","Atlas","Beta"]
return = ["Atlas","Atlas","Atlas","Atlas"]
Every merchant in this hierarchy reaches Atlas.
Example 3
parents = ["A","B"]
children = ["A1","B1"]
loanMerchants = ["B1","A1","B"]
return = ["B","A","B"]
The two independent hierarchies resolve to roots A and B while preserving loan order.

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 is acyclic.
Every loan merchant appears in the hierarchy or is a root business.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a hash map from child to parent. A root is any name that isn't a key in that map. For each loan merchant, climb parents until the name has no entry. That alone is correct, but a long chain repeated across 100000 loans gives O(n * depth), which can hit O(n^2). Fix it with memoization: store the root for every node you visit on the way up, so each node gets resolved once. Do it iteratively, not recursively, because a chain of 100000 can overflow the stack. Union-find with path compression works too, but the map plus cache is simpler. Pitfalls: forgetting that a root used as a loan merchant returns itself, and mutating the order of the output. Keep results aligned to loanMerchants index. If the iterative path-caching logic slips under pressure, StealthCoder is the hedge on the live OA.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Normalize Loan Merchants to Root Businesses cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Affirm's OA.

Affirm reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Normalize Loan Merchants to Root Businesses FAQ

How hard is the Affirm normalize loan merchants problem really?+

Easy to medium. The logic is a map lookup and a parent climb. The difficulty is efficiency at 100000 inputs, since repeated climbs on deep chains get slow. If you add caching, you're done in about twenty lines.

What's the core trick?+

Map each child to its parent, then climb until a name has no parent. Cache the root for every node on the path so later lookups are O(1). That turns the whole thing into roughly linear time.

Should I use recursion or iteration?+

Iteration. The hierarchy can be a single chain of up to 100000 businesses, and recursion can overflow the stack in many languages. Collect the path in a list, find the root, then write the root back for every node in that list.

Could union-find solve this instead?+

Yes. Union each child to its parent, with the parent as the representative, and use path compression on find. It works, but you must keep the parent as the root of the set. The map plus cache approach is shorter and harder to get wrong.

What edge cases should I test before submitting?+

Empty parents and children arrays, where every loan merchant is its own root. A loan merchant that is a root itself. Multiple independent hierarchies like Example 3. Repeated merchants in loanMerchants. And a deep chain to confirm no stack overflow or timeout.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Affirm.

OA at Affirm?
Invisible during screen share
Get it