Merge Taobao Buyer Accounts Sharing Devices or Addresses

Last updated: November 29, 2026

Quick Overview

Each Taobao account comes with a list of identifiers (device IDs, shipping addresses, payment tokens). Two accounts belong to the same real buyer if they share any identifier, directly or through a chain; return the clusters sorted by size descending, each cluster's account IDs sorted.

Alibaba
Coding & Algorithms
Software Engineer
Alibaba
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Each Taobao account comes with a list of identifiers (device IDs, shipping addresses, payment tokens). Two accounts belong to the same real buyer if they share any identifier, directly or through a chain; return the clusters sorted by size descending, each cluster's account IDs sorted.

A coding round in the style of Alibaba's risk control and anti-fraud teams, who link accounts to catch coupon abuse and fake orders around big sales. The interviewer wants to see you model transitive linkage as connected components and pick union find with path compression over repeated pairwise comparisons.

What the Interviewer Expects
  • Recognize transitive sharing as connected components
  • Avoid O(n^2) pairwise comparison by mapping each identifier to its first owning account
  • Implement union find with path compression and union by size
  • Produce deterministic output ordering as specified
  • Handle accounts with no identifiers as singleton clusters
  • Analyze time as near-linear in total identifiers
Key Topics to Cover
union find
connected components
hashing
entity resolution
risk control
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • A single public Wi-Fi device ID links thousands of unrelated accounts. How do you stop such hub identifiers from collapsing everything into one cluster?
  • How would you support new accounts and identifiers arriving online without rebuilding?
  • How would you distribute this over billions of accounts across machines?
  • How would you also return which identifier caused each merge, for an analyst to review?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: accounts, a list of (account_id, identifiers). Identifiers are opaque strings, prefixed by type in the example (dev:, addr:, pay:). Output: list of clusters, largest first, ties broke...

High-Level Design

Build an implicit graph where accounts are nodes and a shared identifier is an edge. We never materialize all edges: for each identifier remember the first account that had it, and union every later a...


Submit Your Answer
Markdown supported