Sizes of Friend Groups
Reported by candidates from Doordash's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
You're looking at a Doordash OA from March 2024 that asks you to find sizes of friend groups. This is a classic union-find or connected components problem dressed up in social graph language. The assessment is testing whether you can identify connected subgroups in an undirected graph and return their sizes. If you're blank on the approach, StealthCoder will show you the pattern in real time so you don't tank this one.
Pattern and pitfall
The core trick: you need to group people into connected components where a connection means they're directly or transitively friends. Union-find (disjoint set union) is the cleanest approach. Build a union operation as you read each friendship pair, then count the size of each component at the end. The pitfall most candidates hit is forgetting to track component sizes during union operations or doing a separate DFS/BFS pass when union-find already gives you the answer. StealthCoder catches these mistakes instantly and shows you the correct structure before you commit buggy code.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Sizes of Friend Groups cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as number of connected components in an undirected graph. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Doordash's OA.
Doordash reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sizes of Friend Groups FAQ
Is this really just union-find?+
Yes. You union each friendship pair and track component sizes. Some candidates overthink it and write DFS or BFS instead. Both work, but union-find is cleaner. If you know the pattern, it's straightforward.
What if the input is 'friendship list' format instead of edges?+
Doesn't matter. Convert it to edges (person A is friends with person B), then union them. The algorithm stays the same. Make sure you handle isolated people (size 1 components) correctly.
Do I need to return the sizes sorted or in a specific order?+
The problem statement wasn't provided, so assume you return a list of sizes in any order unless told otherwise. If the OA specifies sorted, sort them. Read the output spec carefully on the day.
How do I handle a person with no friends?+
They're a component of size 1. Make sure your union-find initialization doesn't skip them. If the input lists people explicitly, include them. If not, you might only process people mentioned in friendships.
Can I solve this with DFS or BFS instead?+
Absolutely. Build an adjacency list, run DFS/BFS from each unvisited node, count sizes. It's slightly more code than union-find but equally valid. Pick whichever you're faster at.