Motive·Software Engineer·Technical Phone Screen
- Implement a Disjoint Set Union (Union-Find) data structure with union by rank and path compression. The API should support union(a, b), connected(a, b), and a count() method returning the number of connected components. Given n nodes and a stream of operations, return the result of each connected query and the component count after each union. Also analyze time and space complexity and discuss thread-safety.
“I got the core implementation down fine, path compression and union by rank are pretty standard once you've seen them.”