Build a Disjoint Set to Group Duplicate Android Crash Reports
Last updated: November 29, 2026
Quick Overview
Implement a reusable disjoint set class whose elements are arbitrary hashable crash signature IDs, supporting add, find, union, connected, set size, and the current number of sets, all in near-constant amortized time.
0
0
0 solved
Implement a reusable disjoint set class whose elements are arbitrary hashable crash signature IDs, supporting add, find, union, connected, set size, and the current number of sets, all in near-constant amortized time.
Crash triage for Android and Play Console merges reports judged to be duplicates, and a Google screen may ask you to build the data structure itself rather than use it. The interviewer is checking API design, both standard optimizations, and that bookkeeping like set counts stays correct under repeated unions.
What the Interviewer Expects
- Exposes a clean API with lazily added elements
- Implements path compression without recursion
- Implements union by size and keeps sizes at roots
- Maintains an accurate count of sets
- Explains the inverse Ackermann bound in plain terms
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Add a method that lists all members of a set efficiently.
- How would you make this thread-safe for a multi-threaded triage service?
- Can you support splitting a set back apart? What would that cost?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Elements are any hashable IDs and may be seen for the first time inside
unionorfind. - Operations:
add,find,union(returns whether a merge happened),connected,set_size, and `num_...
High-Level Design
Store parent and size in dictionaries so IDs need not be dense integers. find walks to the root, then makes a second pass pointing every node on the path straight at the root (full path compress...