Merge Accounts by Shared Attribute
Updated
Problem statement
You are given a list of records, where each record records[i] = [account, attribute] says that an account has an attribute, such as a card number or a phone number. Return all groups of linked accounts.
Two accounts are linked if they have the same attribute. Links carry over: if account A is linked to account B, and B is linked to account C, then A, B and C are in one group, even if A and C share no attribute. So an account with two attributes joins the accounts on both sides into one group. An account that is linked to no other account is a group by itself, so every account is in exactly one group.
Examples
Example 1
records = [["alice","card1"],["bob","card1"],["bob","phone7"],["carol","phone7"],["dave","card9"]]return = [["alice","bob","carol"],["dave"]]alice and bob share card1, and bob and carol share phone7, so all three are one group. dave shares no attribute with any other account, so it is a group by itself.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.
More Amazon Phone Screen questions
- Count Connected ComponentsPHONE SCREEN · Seen Dec 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge k Sorted ListsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Record Linkage Part 3 - Full Connected ComponentStripe · PHONE SCREENStripe interview questions
- Terminal Nodes for Each SourceIndeed · PHONE SCREENIndeed interview questions
- Find All People With the SecretGoogle · PHONE SCREENGoogle interview questions
- Accounts MergeOracle · ONSITE INTERVIEWOracle interview questions
- Find All People With SecretIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Mutual-Friend Referral RecommendationsFireworks AI · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
- Evaluate DivisionApple · PHONE SCREENApple interview questions
- Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
Amazon interview experiences
- Amazon Experienced SDE Onsite Questions: 1 Experience
- Amazon SDE Onsite Interview Questions: 9 Experiences
- Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
- Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
- Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
- Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)