Parse escaped CSV participant data and generate a one-to-one gift exchange in which nobody is assigned to themselves. Cover malformed rows, duplicate emails, small inputs, randomness requirements, reproducible tests, privacy, and possible forbidden-pair extensions.
# Parse a CSV and Generate a Gift Exchange
Implement a small gift-exchange service. The input is CSV text with headers `name,email`. Parse valid participants and return assignments in which every participant gives to exactly one other participant, receives from exactly one participant, and nobody is assigned to themselves.
Explain how randomness is produced, which malformed rows are rejected, and how the result is tested. Assume emails uniquely identify participants. The function should return a structured error when fewer than two valid participants remain or when an email appears more than once.
### Constraints & Assumptions
- Names may contain commas or quotes according to normal CSV escaping rules.
- Leading and trailing whitespace around an email is ignored; email comparison is case-insensitive.
- The exchange does not require uniform sampling from every possible derangement unless the caller explicitly requests that stronger property.
- Do not email participants or persist personal data as part of this exercise.
### Clarifying Questions to Ask
- Is any valid no-self assignment acceptable, or must every derangement be equally likely?
- Are household or historical-pair exclusions required?
- Should invalid rows fail the whole import or be reported individually?
- Must repeated runs be reproducible from a seed for testing?
### What a Strong Answer Covers
```premium-lock What a Strong Answer Covers
```
### Follow-up Questions
- How would you add forbidden pairs?
- How would you provide verifiable randomness?
- How would you safely notify participants without revealing the full assignment graph?
Quick Answer: Parse escaped CSV participant data and generate a one-to-one gift exchange in which nobody is assigned to themselves. Cover malformed rows, duplicate emails, small inputs, randomness requirements, reproducible tests, privacy, and possible forbidden-pair extensions.
Implement a small gift-exchange service. The input is CSV text with headers name,email. Parse valid participants and return assignments in which every participant gives to exactly one other participant, receives from exactly one participant, and nobody is assigned to themselves.
Explain how randomness is produced, which malformed rows are rejected, and how the result is tested. Assume emails uniquely identify participants. The function should return a structured error when fewer than two valid participants remain or when an email appears more than once.
Constraints & Assumptions
Names may contain commas or quotes according to normal CSV escaping rules.
Leading and trailing whitespace around an email is ignored; email comparison is case-insensitive.
The exchange does not require uniform sampling from every possible derangement unless the caller explicitly requests that stronger property.
Do not email participants or persist personal data as part of this exercise.
Clarifying Questions to Ask Guidance
Is any valid no-self assignment acceptable, or must every derangement be equally likely?
Are household or historical-pair exclusions required?
Should invalid rows fail the whole import or be reported individually?
Must repeated runs be reproducible from a seed for testing?
What a Strong Answer Covers Premium
Follow-up Questions Guidance
How would you add forbidden pairs?
How would you provide verifiable randomness?
How would you safely notify participants without revealing the full assignment graph?