This question evaluates ability to model constrained permutations and apply graph-theoretic and combinatorial reasoning to produce a single circular ordering where adjacent elements come from different sub-groups.
You are given a “big family” composed of several sub-families. Each sub-family is a list of unique person IDs/names.
Example input:
[[A1, A2], [B1, B2], [C1]]
You need to produce a circular gift-exchange chain that includes every person exactly once, such that:
p0, p1, ..., p(n-1)
, then gifts go
p0→p1, p1→p2, ..., p(n-2)→p(n-1), p(n-1)→p0
.
For [[A1, A2], [B1, B2], [C1]], a valid circular ordering could be:
[A1, B1, A2, B2, C1]
This implies: A1→B1→A2→B2→C1→A1, and no adjacent pair is from the same sub-family.