You are given genealogy information for a set of chickens. The data consists of parent → child relationships (e.g., (parentId, childId) pairs). Not every chicken necessarily appears in every role, and the data may describe multiple independent family groups.
Write a function that, given two chicken IDs a and b, determines whether they have a blood relationship.
For this interview question, treat two chickens as “blood-related” if they belong to the same family lineage, meaning:
relations
, where each pair
(p, c)
indicates
p
is a parent of
c
.
a
and
b
.
true
if
a
and
b
are blood-related under the definition above, otherwise
false
.
a
or
b
may not appear in
relations
.
Given relations: (1,2), (1,3), (3,4), (10,11):
(2,4)
→
true
(share ancestor
1
)
(2,11)
→
false
(different family groups)
(3,4)
→
true
(ancestor/descendant)