← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Coding screen for a Software Engineer role at Amazon, focused entirely on Union-Find. Pretty narrow scope but you really need to know the internals cold, not just the concept.

Questions Asked (1)

Q1

Implement Union-Find with path compression and union-by-rank, then apply it to a graph or connectivity problem.

Algorithms & Data Structures
Author's notes

The core of the whole round.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly defining the Union-Find data structure with path compression and union-by-rank, explaining how each optimization improves efficiency. Then, walk through a concrete connectivity problem (e.g., number of connected components in a graph or detecting cycles) and demonstrate how to apply the data structure step by step. Finally, analyze the time complexity and discuss potential edge cases.

Pro tip: Emphasize the near-constant time complexity (inverse Ackermann function) and relate it to real-world scalability, showing you understand why this matters for large-scale systems like Amazon's. Also, mention that you can implement it with either 0-indexed or 1-indexed arrays, and clarify your choice.

1. Explain the Data Structure

Describe the parent array and rank/size array, and how they represent disjoint sets. Clarify that each set has a representative (root).

2. Implement Core Operations

Detail the find operation with path compression (recursive or iterative) and the union operation with union-by-rank, including tie-breaking rules.

3. Apply to a Connectivity Problem

Choose a specific problem (e.g., number of connected components in an undirected graph, or detecting cycles) and show how to process edges using union and find.

4. Analyze Complexity and Optimizations

State the amortized time complexity per operation (O(α(n))) and explain why path compression and union-by-rank together yield near-constant time.

5. Discuss Edge Cases and Extensions

Mention handling of duplicate edges, self-loops, and disconnected graphs. Optionally, discuss variations like union-by-size or weighted union-find.

Key Points to Mention

  • Path compression: flattening the tree during find to reduce future traversal time.
  • Union by rank: attaching smaller tree to larger tree to keep depth logarithmic.
  • Amortized time complexity: O(α(n)) per operation, where α is the inverse Ackermann function.
  • Application: counting connected components in a graph by initializing each node as its own set and unioning edges.
  • Cycle detection: if find(u) == find(v) before union, a cycle exists.
  • Space complexity: O(n) for parent and rank arrays.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.