Answer Whether Two Customers Share an Amazon Household
Last updated: November 29, 2026
Quick Overview
Given n customer accounts and a list of household links between pairs of accounts, answer a batch of queries asking whether two accounts end up in the same household, where links are transitive.
Amazon
November 29, 20260
0
0 solved
Given n customer accounts and a list of household links between pairs of accounts, answer a batch of queries asking whether two accounts end up in the same household, where links are transitive.
Amazon Household lets accounts share Prime benefits, and linked accounts form connected groups. This online assessment style question checks whether you reach for union find with path compression and union by size instead of rerunning BFS for every query.
What the Interviewer Expects
- Model links as unions in a disjoint set structure
- Implement find with path compression or halving
- Use union by size or rank
- Answer each query with two finds
- State near-constant amortized cost per operation
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
- How would you also return the size of each household?
- Amazon Household caps membership; how would you reject a link that would exceed the cap?
- What if links can be removed later?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: n accounts labeled 0..n-1, links as pairs, and queries as pairs. Output: a boolean per query. Links are undirected and transitive (A with B and B with C puts A and C together)....
High-Level Design
Running BFS per query costs O(n + m) each, which is too slow for large query batches. A disjoint set union (DSU) keeps a parent pointer per account; the root identifies the household.
union(a, b)...