Problem context and objectives
Mission briefing
Puzzle systems engineer · A game mechanic is behaving incorrectly
Let shared emails reveal identity: The Account Constellations.
Brute force may pass the demo but fail when the world fills with players.
How you win
- 1Recognize when Union Find over shared keys matches the clues
- 2Keep this true after every move: accounts share a component exactly when a chain of shared emails connects them
- 3Reach the result within O(total emails alpha(accounts) + output sorting)
Rules and pressure
- Target cost: O(total emails alpha(accounts) + output sorting)
- State rule: accounts share a component exactly when a chain of shared emails connects them
Lesson 1 of 3
Live algorithm trace
Union Find over shared keys
Complete execution1 of 6
John:a,b
account
John:a,c
Mary:m
John:z
Initialize one set per account row and an empty email ownership map.
1
parent = range(account count)2
emailOwner = empty map3
for every account email4
union with its previous owner if seen5
group each email by final root6
sort emails and groups7
return merged accountsparent = [0,1,2,3]emailOwner = {}
Truth to preserve / Cost target
Truth to preserve
accounts share a component exactly when a chain of shared emails connects them
Cost target
O(total emails alpha(accounts) + output sorting)
Treat each account row as a node. The first account that owns an email becomes its representative candidate; seeing that email again unions the two account rows. Finally, group every email by its account root.
Your call · What should guide every step of this algorithm?