PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Wave

Construct a circular gift exchange across families

Last updated: Mar 29, 2026

Quick Overview

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.

  • hard
  • Wave
  • Coding & Algorithms
  • Software Engineer

Construct a circular gift exchange across families

Company: Wave

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

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: 1. **No one gives a gift to someone in the same sub-family.** - In the chain order, this means **adjacent people** (giver → receiver) must come from **different** sub-families. 2. The arrangement must form **one cycle** (a single circular chain). - If the output order is `p0, p1, ..., p(n-1)`, then gifts go `p0→p1, p1→p2, ..., p(n-2)→p(n-1), p(n-1)→p0`. ### Input - A list of sub-families, where each sub-family is a list of strings (or integers) representing people. ### Output - Return **any** valid circular ordering of all people (or equivalently, the directed gift pairs), **or** indicate that it is **impossible**. ### Notes / Clarifications - People are distinct across all sub-families. - The chain must include everyone exactly once. - If there are multiple valid answers, any one is acceptable. ### Example (one possible valid output) 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.

Quick Answer: 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.

Wave logo
Wave
Jan 6, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
1
0
Loading...

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:

  1. No one gives a gift to someone in the same sub-family.
    • In the chain order, this means adjacent people (giver → receiver) must come from different sub-families.
  2. The arrangement must form one cycle (a single circular chain).
    • If the output order is p0, p1, ..., p(n-1) , then gifts go p0→p1, p1→p2, ..., p(n-2)→p(n-1), p(n-1)→p0 .

Input

  • A list of sub-families, where each sub-family is a list of strings (or integers) representing people.

Output

  • Return any valid circular ordering of all people (or equivalently, the directed gift pairs), or indicate that it is impossible .

Notes / Clarifications

  • People are distinct across all sub-families.
  • The chain must include everyone exactly once.
  • If there are multiple valid answers, any one is acceptable.

Example (one possible valid output)

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.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Wave•More Software Engineer•Wave Software Engineer•Wave Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.