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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

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
Union-Find
Data Structure Design
Path Compression
Amortized Analysis
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Elements are any hashable IDs and may be seen for the first time inside union or find.
  • 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...


Submit Your Answer
Markdown supported