FastPrepMerge Accounts by Shared Attribute
Problems/Merge Accounts by Shared Attribute

Merge Accounts by Shared Attribute

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN

Updated Dec 2026

QuestionExamples

Problem statement

Source note: Reported in an Amazon phone screen for a full-time software engineer role on the AWS Payments team. After behavioral questions, there was one coding problem. Each record pairs an account with an attribute. Accounts with the same attribute are linked, an account with two attributes links the accounts on both sides, and the task is to find every group of linked accounts. The candidate's own idea, worked out after the call, was to build lookups in both directions and collect each group with a breadth-first search.

The report gives no function signature, output order, rule for an account with no links, or limits. Here we return every group, including groups of one account, sort the accounts in each group and sort the groups by their first account, treat account names and attribute names as separate, allow repeated records, and set our own small limits.

Our version is about 80% the same as the reported question.

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.

The problem statement continues
Pro

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.

02 · Example 2
FastPrep Pro
Reported in 1 Amazon interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week

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)
See Amazon hiring insights
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week