Problem · Graph

Fraud Ring Size

Learn this problem
MediumStripeOA
See Stripe hiring insights

Problem statement

Direct links alone may miss sophisticated fraud rings. A fraud ring is the full set of users connected by any chain of shared identifiers.

Each transaction log entry is formatted as user_id,device_id,credit_card. Two users are connected if they share a device or a credit card, either directly or through other connected users.

Given the log and a target user, return the number of unique users in the fraud ring containing the target user. Include the target user in the count.

Function

getFraudRingSize(transactions: String[], targetUser: String) → int

Complete getFraudRingSize.

  • String transactions[n]: transaction rows formatted user_id,device_id,credit_card
  • String targetUser: the user to investigate

Returns

int: the fraud ring size.

Examples

Example 1

transactions = ["Alice,D1,CC1","Bob,D1,CC2","Charlie,D2,CC2","David,D3,CC3","Eve,D3,CC4"]targetUser = "Alice"return = 3

Alice connects to Bob by device D1, and Bob connects to Charlie by card CC2. David and Eve are in a separate cluster.

Example 2

transactions = ["A,D1,C1","B,D2,C2","C,D3,C3"]targetUser = "A"return = 1

No other user shares A's identifiers.

Constraints

  • 0 <= transactions.length <= 10^5
  • User IDs, device IDs, and credit-card hashes contain no commas.

More Stripe problems

drafts saved locally
public int getFraudRingSize(String[] transactions, String targetUser) {
  // write your code here
}
transactions["Alice,D1,CC1","Bob,D1,CC2","Charlie,D2,CC2","David,D3,CC3","Eve,D3,CC4"]
targetUser"Alice"
expected3
checking account