Reported September 2026
Googleunion find

Determine Whether Two Horses Are Genetically Related

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

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

Google's September 2026 OA has a horse genealogy question, and it looks friendlier than it is. You're given parallel arrays of horses, mothers and fathers, and asked if two horses are connected. It's a connected-components problem on an undirected graph, and union-find or a plain BFS both work. The trap is reading it as a family tree with direction. If you're taking this OA in the next couple of days, learn the shape now. StealthCoder is the backup if your mind goes blank mid-assessment.

The problem

The International Horse Racing Committee maintains birth-certificate data for a collection of horses. Each record identifies a horse and, when known, its mother and father.
Each position i describes one horse:
horseIds[i] is the horse's identifier.
motherIds[i] is its mother's identifier, or the empty string "" when the mother is unknown.
fatherIds[i] is its father's identifier, or the empty string "" when the father is unknown.
Relationship rule
For this exercise, assume every non-empty parent entry creates an undirected relationship edge between the horse and that parent. Two horses are genetically related when a path of one or more such parent-child edges connects them. A horse is also related to itself.
A non-empty parent identifier may refer to a horse that does not have its own record in horseIds.
Required result
Return true when horseA and horseB belong to the same connected component of this relationship graph. Otherwise, return false.

Function
areHorsesRelated(horseIds: String[], motherIds: String[], fatherIds: String[], horseA: String, horseB: String) → boolean

Examples
Example 1
horseIds = ["Nova","Comet","Blaze"]
motherIds = ["","Nova",""]
fatherIds = ["","",""]
horseA = "Nova"
horseB = "Comet"
return = true
Comet lists Nova as its mother, so one parent-child edge directly connects the queried horses.
Example 2
horseIds = ["Atlas","Bella","Colt"]
motherIds = ["","","Atlas"]
fatherIds = ["","","Bella"]
horseA = "Atlas"
horseB = "Bella"
return = true
The path Atlas - Colt - Bella connects the two queried horses through their shared child record.
Example 3
horseIds = ["A","B","C","D"]
motherIds = ["","A","","C"]
fatherIds = ["","","",""]
horseA = "B"
horseB = "D"
return = false
A - B and C - D are separate connected components, so no relationship path joins B to D.
Example 4
horseIds = ["Solo"]
motherIds = [""]
fatherIds = [""]
horseA = "Solo"
horseB = "Solo"
return = true
The two query identifiers name the same horse, which is related to itself by definition.

Constraints
1 <= horseIds.length <= 100,000.
motherIds.length == horseIds.length and fatherIds.length == horseIds.length.
Every value in horseIds is a unique, non-empty identifier with length from 1 to 50.
Every value in motherIds and fatherIds is either the empty string or an identifier with length from 1 to 50.
horseA and horseB both appear in horseIds.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to ignore the word genetics. Every non-empty parent entry is just an undirected edge between a horse and that parent. So you're asking if horseA and horseB share a connected component. Use union-find with a hash map from string to index, or build an adjacency map and run BFS from horseA. The common first-attempt mistake is assuming parents always have their own record. The statement says a parent can appear without being in horseIds, so you must add those IDs on the fly instead of indexing into a fixed array. The other mistake is treating the empty string as a real node, which wrongly joins every orphan into one giant component. Skip empty strings entirely. Also handle horseA equal to horseB, which returns true. With 100,000 records, avoid recursive DFS that can overflow the stack. Union-find with path compression is near linear. If you blank on the live OA, StealthCoder can supply this pattern as a safety net.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Determine Whether Two Horses Are Genetically Related 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Determine Whether Two Horses Are Genetically Related FAQ

What's the trick in the Google horse relationship problem?+

Treat each non-empty mother or father entry as an undirected edge, then check if the two query horses land in the same connected component. Direction doesn't matter. Union-find or BFS over a hash map of string IDs both solve it cleanly.

Why does the empty string cause wrong answers?+

The empty string means the parent is unknown, not a horse named blank. If you union it like a real ID, every horse with a missing parent gets connected through a phantom node, and unrelated horses return true. Skip empty entries completely.

Do parents always appear in horseIds?+

No. The problem says a parent identifier may refer to a horse with no record of its own. Your map or union-find must create nodes lazily when it first sees an ID, whether as a horse or as a parent.

Should I use union-find or BFS?+

Either works for 100,000 records. Union-find with path compression is short to write and avoids recursion depth issues. BFS needs an adjacency map but is just as fast. Pick the one you can write without bugs under pressure.

How do I prepare for this in 48 hours?+

Write union-find with string keys once from memory, then do one BFS version. Test the edge cases: same horse for both queries, missing parent records, and all empty parents. That covers what this question punishes.

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

OA at Google?
Invisible during screen share
Get it