Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Account Constellations

Learn
Play
Prove
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

  1. 1Recognize when Union Find over shared keys matches the clues
  2. 2Keep this true after every move: accounts share a component exactly when a chain of shared emails connects them
  3. 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 execution
1 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.

1parent = range(account count)
2emailOwner = empty map
3for every account email
4union with its previous owner if seen
5group each email by final root
6sort emails and groups
7return merged accounts
parent = [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?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead