AlgoViz
← All drills
🧠 Drill · Think it through

Friend circles forming

The problem

People keep becoming friends one pair at a time. After all the friendships are added, count how many separate friend groups exist, where being friends (even friends-of-friends) puts people in the same group. New connections keep merging groups together over time.

Don't jump to code. Walk the four questions an expert asks first — you'll build the habit, not just the answer.

1

Restate it

Before anything else — did you read what's actually being asked? Strip the story to the bare goal.

Strip away the story. What are we really tracking?